sresult.setSuccessful(true);
sresult.setResponseMessage(getSuccess());
sresult.setResponseCode(getSuccessCode());
if (this.testCase != null){
// create a new TestResult
TestResult tr = new TestResult();
final TestCase theClazz = this.testCase;
try {
if (setUpMethod != null){
setUpMethod.invoke(this.testObject,new Object[0]);
}
sresult.sampleStart();
tr.startTest(this.testCase);
// Do not use TestCase.run(TestResult) method, since it will
// call setUp and tearDown. Doing that will result in calling
// the setUp and tearDown method twice and the elapsed time
// will include setup and teardown.
tr.runProtected(theClazz, protectable);
tr.endTest(this.testCase);
sresult.sampleEnd();
if (tearDownMethod != null){
tearDownMethod.invoke(testObject,new Object[0]);
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof AssertionFailedError){
tr.addFailure(theClazz, (AssertionFailedError) cause);
} else if (cause instanceof AssertionError) {
// Convert JUnit4 failure to Junit3 style
AssertionFailedError afe = new AssertionFailedError(cause.toString());
// copy the original stack trace
afe.setStackTrace(cause.getStackTrace());
tr.addFailure(theClazz, afe);
} else if (cause != null) {
tr.addError(theClazz, cause);
} else {
tr.addError(theClazz, e);
}
} catch (IllegalAccessException e) {
tr.addError(theClazz, e);
} catch (IllegalArgumentException e) {
tr.addError(theClazz, e);
}
if ( !tr.wasSuccessful() ){
sresult.setSuccessful(false);
StringBuilder buf = new StringBuilder();
StringBuilder buftrace = new StringBuilder();
Enumeration<TestFailure> en;
if (getAppendError()) {
en = tr.failures();
if (en.hasMoreElements()){
sresult.setResponseCode(getFailureCode());
buf.append( getFailure() );
buf.append("\n");
}
while (en.hasMoreElements()){
TestFailure item = en.nextElement();
buf.append( "Failure -- ");
buf.append( item.toString() );
buf.append("\n");
buftrace.append( "Failure -- ");
buftrace.append( item.toString() );
buftrace.append("\n");
buftrace.append( "Trace -- ");
buftrace.append( item.trace() );
}
en = tr.errors();
if (en.hasMoreElements()){
sresult.setResponseCode(getErrorCode());
buf.append( getError() );
buf.append("\n");
}