annotations.add(new AnnotationMetadataBuilder(BEFORE_CLASS));
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("helper.setUp();");
final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
getId(), Modifier.PUBLIC | Modifier.STATIC,
setUpMethodName, JavaType.VOID_PRIMITIVE,
AnnotatedJavaType.convertFromJavaTypes(SETUP_PARAMETERS),
new ArrayList<JavaSymbolName>(), bodyBuilder);
methodBuilder.setAnnotations(annotations);
builder.addMethod(methodBuilder);
}
// Prepare tearDown method signature
final JavaSymbolName tearDownMethodName = new JavaSymbolName("tearDown");
final MethodMetadata tearDownMethod = getGovernorMethod(
tearDownMethodName, TEARDOWN_PARAMETERS);
if (tearDownMethod != null) {
Validate.notNull(
MemberFindingUtils.getAnnotationOfType(
tearDownMethod.getAnnotations(), AFTER_CLASS),
"Method 'tearDown' on '%s' must be annotated with @AfterClass",
destination.getFullyQualifiedTypeName());
}
else {
// Add the method via the ITD
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(AFTER_CLASS));
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("helper.tearDown();");
final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
getId(),
Modifier.PUBLIC | Modifier.STATIC,
tearDownMethodName,
JavaType.VOID_PRIMITIVE,
AnnotatedJavaType.convertFromJavaTypes(TEARDOWN_PARAMETERS),
new ArrayList<JavaSymbolName>(), bodyBuilder);
methodBuilder.setAnnotations(annotations);
builder.addMethod(methodBuilder);
}
}