CompilationUnitBuilder compilationUnitBuilder = new CompilationUnitBuilder();
compilationUnitBuilder.buildComment(FileComments.GENERATOR_COMMENT);
TypeDeclaration typeDeclaration = JavaParserUtils.findTargetTypeDeclaration(sourceCU, javaFile);
List<MethodDeclaration> methodDeclarations = MembersFilter.findMethodsFrom(typeDeclaration);
String className = typeDeclaration.getName();
ClassTypeBuilder classTypeBuilder = new ClassTypeBuilder(className + Consts.TEST_SUFFIX);
List<Comment> existComments = testCU.getComments();
compilationUnitBuilder.addComments(existComments);
PackageDeclaration existPackageDeclaration = testCU.getPackage();
compilationUnitBuilder.addPackage(existPackageDeclaration);
//process import
List<ImportDeclaration> existImports = testCU.getImports();
compilationUnitBuilder.addImports(existImports);
//process methods
for (MethodDeclaration methodDeclaration : methodDeclarations) {
String methodName = methodDeclaration.getName();
MethodDeclaration testMethodDeclaration = FileChecker.isTestCaseExist(testCU,
methodDeclaration);
boolean methodExist = (testMethodDeclaration == null ? false : true);
if (!methodExist) {
classTypeBuilder.buildMethod(methodName + Consts.TEST_SUFFIX, methodDeclaration);
} else if (methodExist) {
classTypeBuilder.addMethod(testMethodDeclaration);
}
}
compilationUnitBuilder.buildClass(classTypeBuilder.build());
return compilationUnitBuilder;
}