* @param webPageTestRunner
*/
protected void addBuildCandidates(final NewConcreteType testBuilder, final Type webPageTestRunner) {
Checker.notNull("parameter:testBuilder", testBuilder);
final GeneratorContext context = this.getGeneratorContext();
final Method method = this.getTestBuilder().findMethod(Constants.BUILD_CANDIDATES_METHOD, Collections.EMPTY_LIST);
final NewMethod newMethod = method.copy(testBuilder);
newMethod.setAbstract(false);
newMethod.setFinal(true);
newMethod.setNative(false);
final BuildCandidatesTemplatedFile body = new BuildCandidatesTemplatedFile();
newMethod.setBody(body);
final Type voidType = this.getGeneratorContext().getVoid();
final List<Method> methods = new ArrayList<Method>();
// find and add public methods that start with test
final VirtualMethodVisitor testMethodFinder = new VirtualMethodVisitor() {
protected boolean visit(final Method method) {
while (true) {
if (method.getVisibility() != Visibility.PUBLIC) {
break;
}
if (false == method.getName().startsWith(Constants.TEST_METHOD_NAME_PREFIX)) {
context.debug("Ignoring method " + method + " because it doesnt start with public.");
break;
}
// test method must return void
final Type returnType = method.getReturnType();
if (returnType != voidType) {
throwTestMethodDoesntReturnVoid(method);
}
// test method must have no parameters.
final List<MethodParameter> parameters = method.getParameters();
if (false == parameters.isEmpty()) {
throwTestMethodHasParameters(method);
}
// public void test*() method found...
methods.add(method);
break;
}
return false;
}
protected boolean skipJavaLangObjectMethods() {
return true;
}
};
testMethodFinder.start(webPageTestRunner);
Collections.sort(methods, new Comparator<Method>() {
public int compare(final Method method, final Method otherMethod) {
return TestBuilderGenerator.this.getOrder( method) - TestBuilderGenerator.this.getOrder(otherMethod);
}
});
final Iterator<Method> iterator = methods.iterator();
while (iterator.hasNext()) {
final Method testMethod = iterator.next();
body.addTestMethod(testMethod);
context.debug("Adding test method " + testMethod);
}
}