[testng] 95/355: Invoker: better error message in case of expected exceptions
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:52 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.
commit e919e3dd5edc2dd81296a00446211092f25f54f7
Author: Vladislav Rassokhin <vladrassokhin at gmail.com>
Date: Sun Nov 23 01:45:35 2014 +0300
Invoker: better error message in case of expected exceptions
---
src/main/java/org/testng/internal/Invoker.java | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/testng/internal/Invoker.java b/src/main/java/org/testng/internal/Invoker.java
index 2a9d7b6..a40e94f 100644
--- a/src/main/java/org/testng/internal/Invoker.java
+++ b/src/main/java/org/testng/internal/Invoker.java
@@ -42,6 +42,7 @@ import org.testng.xml.XmlTest;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -1450,15 +1451,15 @@ public class Invoker implements IInvoker {
}
} else if (isSkipExceptionAndSkip(ite)){
status = ITestResult.SKIP;
- } else if (ite != null && expectedExceptionsHolder != null) {
+ } else if (expectedExceptionsHolder != null) {
testResult.setThrowable(
- new TestException("Expected exception "
- + expectedExceptionsHolder.expectedClasses[0].getName()
- + " but got " + ite, ite));
+ new TestException("Expected exception of " +
+ getExpectedExceptionsPluralize(expectedExceptionsHolder)
+ + " but got " + ite, ite));
status= ITestResult.FAILURE;
} else {
handleException(ite, testMethod, testResult, failureCount++);
- status= testResult.getStatus();
+ status = testResult.getStatus();
}
}
@@ -1468,7 +1469,7 @@ public class Invoker implements IInvoker {
if (classes != null && classes.length > 0) {
testResult.setThrowable(
new TestException("Method " + testMethod + " should have thrown an exception of "
- + expectedExceptionsHolder.expectedClasses[0]));
+ + getExpectedExceptionsPluralize(expectedExceptionsHolder)));
status= ITestResult.FAILURE;
}
}
@@ -1517,6 +1518,18 @@ public class Invoker implements IInvoker {
return removeResultsToRetryFromResult(resultsToRetry, result, failureCount);
}
+ private String getExpectedExceptionsPluralize(final ExpectedExceptionsHolder holder) {
+ StringBuilder sb = new StringBuilder();
+ if (holder.expectedClasses.length > 1) {
+ sb.append("any of types ");
+ sb.append(Arrays.toString(holder.expectedClasses));
+ } else {
+ sb.append("type ");
+ sb.append(holder.expectedClasses[0]);
+ }
+ return sb.toString();
+ }
+
private boolean isSkipExceptionAndSkip(Throwable ite) {
return SkipException.class.isAssignableFrom(ite.getClass()) && ((SkipException) ite).isSkip();
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list