if (testInstance != null)
{
try
{
TestResult result = null;
try
{
try
{
testInstance = ClassLoaderAdapterCallback.enhance(getClass().getClassLoader(),
testInstance.getClass().getClassLoader(), testInstance, testClass);
testInstance.getClass();
}
catch (Exception e)
{
System.out.println("Could not enhance test class. Falling back to un-proxied invocation.");
}
Method method = testInstance.getClass().getMethod(testMethodExecutor.getMethod().getName());
Annotation[] annotations = method.getAnnotations();
for (Annotation annotation : annotations)
{
if ("org.junit.Ignore".equals(annotation.getClass().getName()))
{
result = new TestResult(Status.SKIPPED);
}
}
if (result == null)
{
try
{
System.out.println("Executing test method: "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()");
try
{
invokeBefore(testInstance.getClass(), testInstance);
method.invoke(testInstance);
}
catch (Exception e)
{
throw e;
}
finally
{
invokeAfter(testInstance.getClass(), testInstance);
}
result = new TestResult(Status.PASSED);
}
catch (InvocationTargetException e)
{
if (e.getCause() != null && e.getCause() instanceof Exception)
throw (Exception) e.getCause();
else
throw e;
}
}
}
catch (AssertionError e)
{
result = new TestResult(Status.FAILED, e);
}
catch (Exception e)
{
result = new TestResult(Status.FAILED, e);
Throwable cause = e.getCause();
while (cause != null)
{
if (cause instanceof AssertionError)
{
result = new TestResult(Status.FAILED, cause);
break;
}
cause = cause.getCause();
}
}