// Go through all the results and create a TestResult for each of them
//
List<ITestResult> resultsToRetry = Lists.newArrayList();
for (int i = 0; i < result.size(); i++) {
ITestResult testResult = result.get(i);
Throwable ite= testResult.getThrowable();
int status= testResult.getStatus();
// Exception thrown?
if (ite != null) {
// Invocation caused an exception, see if the method was annotated with @ExpectedException
if (isExpectedException(ite, expectedExceptionsHolder)) {
if (messageRegExpMatches(expectedExceptionsHolder.messageRegExp, ite)) {
testResult.setStatus(ITestResult.SUCCESS);
status= ITestResult.SUCCESS;
}
else {
testResult.setThrowable(
new TestException("The exception was thrown with the wrong message:" +
" expected \"" + expectedExceptionsHolder.messageRegExp + "\"" +
" but got \"" + ite.getMessage() + "\"", ite));
status= ITestResult.FAILURE;
}
} else if (ite != null && expectedExceptionsHolder != null) {
testResult.setThrowable(
new TestException("Expected exception "
+ expectedExceptionsHolder.expectedClasses[0].getName()
+ " but got " + ite, ite));
status= ITestResult.FAILURE;
}
else if (SkipException.class.isAssignableFrom(ite.getClass())){
SkipException skipEx= (SkipException) ite;
if(skipEx.isSkip()) {
status = ITestResult.SKIP;
}
else {
handleException(ite, testMethod, testResult, failureCount++);
status = ITestResult.FAILURE;
}
}
else {
handleException(ite, testMethod, testResult, failureCount++);
status= testResult.getStatus();
}
}
// No exception thrown, make sure we weren't expecting one
else if(status != ITestResult.SKIP && expectedExceptionsHolder != null) {
Class<?>[] classes = expectedExceptionsHolder.expectedClasses;
if (classes != null && classes.length > 0) {
testResult.setThrowable(
new TestException("Method " + testMethod + " should have thrown an exception of "
+ expectedExceptionsHolder.expectedClasses[0]));
status= ITestResult.FAILURE;
}
}
testResult.setStatus(status);
boolean retry = false;
if (testResult.getStatus() == ITestResult.FAILURE) {
IRetryAnalyzer retryAnalyzer = testMethod.getRetryAnalyzer();
if (retryAnalyzer != null && failedInstances != null) {
retry = retryAnalyzer.retry(testResult);
}
if (retry) {
resultsToRetry.add(testResult);
if (failedInstances != null) {
failedInstances.add(testResult.getInstance());
}
}
}
if (!retry || collectResults) {
// Collect the results