Package intellijcoder.model

Examples of intellijcoder.model.Problem


public class SolutionCodeBuilderTest {
    private CodeBuilder codeBuilder = new SolutionCodeBuilder();

    @Test
    public void testBasicClassTemplateStructure() throws Exception {
        final Problem problem = make(a(ProblemMaker.Problem, with(className, "Lottery"),
                with(returnType, "String[]"), with(methodName, "sortByOdds"),
                with(paramTypes, new String[]{"String[]"}), with(paramNames, new String[] {"rules"})));
        final String[] expectedTemplate = {"public class Lottery","{","public String[]","sortByOdds","(","String[]","rules",")","{","}","}"};
        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }
View Full Code Here


        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }

    @Test
    public void methodReturnsFalseForPrimitiveBooleanReturnType() throws Exception {
        final Problem problem = make(a(Problem, with(returnType, "boolean")));
        final String[] expectedTemplate = {"boolean","{","return false", "}"};
        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }
View Full Code Here

        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }

    @Test
    public void methodReturnsZeroForPrimitiveNumberReturnType() throws Exception {
        final Problem problem = make(a(Problem, with(returnType, "double")));
        final String[] expectedTemplate = {"double","{","return 0", "}"};
        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }
View Full Code Here

        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }

    @Test
    public void methodReturnsNullForObjectReturnType() throws Exception {
        final Problem problem = make(a(Problem, with(returnType, "String[]")));
        final String[] expectedTemplate = {"String[]","{","return null", "}"};
        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }
View Full Code Here

        verifyGeneratedClassTemplate(problem, expectedTemplate);
    }

    @Test
    public void repeatingCallsToBuildGenerateTheSameCode() throws Exception {
        Problem problem = make(a(Problem));
        String code1 = codeBuilder.build(problem);
        String code2 = codeBuilder.build(problem);
        assertEquals("generated code", code1, code2);
    }
View Full Code Here

        }

        private void processRequest(Request request, ObjectInputStream objectInputStream, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException, IntelliJCoderException {
            switch (request) {
                case CREATE_PROBLEM_WORKSPACE: {
                    Problem problem = (Problem) objectInputStream.readObject();
                    workspaceManager.createProblemWorkspace(problem);
                    objectOutputStream.writeObject(Response.OK);
                }
                break;
                case GET_SOLUTION_SOURCE: {
View Full Code Here

    }

    private Matcher<Problem> hasMethodSignature(final String returnType, final String methodName, final String paramType, final String paramName) {
        return new BaseMatcher<Problem>() {
            public boolean matches(Object o) {
                Problem problem = (Problem) o;
                return problem.getReturnType().equals(returnType)
                        && problem.getMethodName().equals(methodName)
                        && problem.getParamTypes()[0].equals(paramType)
                        && problem.getParamNames()[0].equals(paramName);
            }

            public void describeTo(Description description) {
                description.appendText("returnType=" + returnType + ", methodName=" + methodName + ", parameter=" + paramType + " " + paramName);
            }
View Full Code Here

    private CodeBuilder testBuilder = context.mock(CodeBuilder.class, "test");
    IdeWorkspaceManager workspaceManager = new IdeWorkspaceManager(ide, solutionBuilder, testBuilder);

    @Test
    public void projectModuleNamedAfterProblemClassName() throws Exception {
        final Problem problem = make(a(Problem, with(className, "Lottery")));
        context.checking(new Expectations(){{
            oneOf(ide).createModule(with(equal("Lottery")), with(any(String.class)), with(any(String.class)));
            ignoring(solutionBuilder);
            ignoring(testBuilder);
        }});
View Full Code Here

    }


    @Test
    public void getsSolutionSourceFromIde() throws Exception {
        final Problem problem = make(a(Problem));
        context.checking(new Expectations(){{
            atLeast(1).of(ide).getClassSource("Lottery");
            ignoring(ide).createModule(with(any(String.class)), with(any(String.class)), with(any(String.class)));
            ignoring(solutionBuilder);
            ignoring(testBuilder);
View Full Code Here

        workspaceManager.getSolutionSource("Lottery");
    }

    @Test
    public void usesCodeBuilderToGetSolutionClassTemplate() throws Exception {
        final Problem problem = make(a(Problem));
        context.checking(new Expectations(){{
            allowing(solutionBuilder).build(problem); will(returnValue("class template"));
            oneOf(ide).createModule(with(any(String.class)), with(equal("class template")), with(any(String.class)));
            ignoring(testBuilder);
        }});
View Full Code Here

TOP

Related Classes of intellijcoder.model.Problem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.