/** * Generates the test cases for the state machine in {@link StateMachine#getInstance()} and writes * the file to the given output path. * * @param outputClassName The simple name of the generate class containing the generated test * cases * @return The source code for the generated test class */ public static String generate(String outputClassName) { final StateMachine machine = StateMachine.getInstance(); final RoundTripPathTreeNode tree = RoundTripPathTreeNode.build(machine.getStartState()); final List<BodyDeclaration> methods = generateTestMethods(tree); final ClassOrInterfaceDeclaration testClass = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, outputClassName); testClass.setMembers(methods); final CompilationUnit file = new CompilationUnit( new PackageDeclaration(new NameExpr(machine.getPackageName())), generateImports(Assert.class, Test.class), Collections.<TypeDeclaration>singletonList(testClass)); return file.toString(); }