for (Method method : testClass.getDeclaredMethods()) {
int modifiers = method.getModifiers();
if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)
&& method.getAnnotation(Ignore.class) == null) {
Test testAnnotation = method.getAnnotation(Test.class);
if (testAnnotation != null) {
for (Method setup : setups) {
setup.invoke(instance, (Object[]) null);
}
Class expectedException = testAnnotation.expected();
// can't for the life of me get eclipse to be able to
// resolve Test.None directly
if (expectedException.getName().equals(
"org.junit.Test$None")) // why the hell doesn't this
// just return null?
{
expectedException = null;
}
try {
method.invoke(instance, (Object[]) null);
} catch (Exception e) {
if (expectedException == null) {
System.out.println(testClass.getName() + "."
+ method.getName() + ": "
+ e.getCause().getMessage());
new BufferedReader(new InputStreamReader(System.in))
.readLine();
} else {
// is there a cleaner way of saying this?
if (!e.getCause().getClass().equals(
testAnnotation.expected())) {
System.out.println(testClass.getName() + "."
+ method.getName() + ": "
+ "Exception expected: "
+ testAnnotation.expected().getName()
+ ", Exception thrown: "
+ e.getCause().getMessage());
new BufferedReader(new InputStreamReader(
System.in)).readLine();
}
expectedException = null;
}
}
if (expectedException != null) {
System.out.println(testClass.getName() + "."
+ method.getName() + ": "
+ "Expected exception not thrown: "
+ testAnnotation.expected().getName());
new BufferedReader(new InputStreamReader(System.in))
.readLine();
}
for (Method tearDown : tearDowns) {