This is an automated email from the git hooks/post-receive script. eugene-guest pushed a commit to annotated tag testng-6.9.5 in repository testng.
commit c50c280b710dc2a33f76f24382242d07e74a268a Author: Julien Herr <[email protected]> Date: Thu Jun 4 13:19:35 2015 +0200 Refactor ExpectedExceptionsHolder --- .../testng/internal/ExpectedExceptionsHolder.java | 24 +++++++++++----------- src/main/java/org/testng/internal/Invoker.java | 24 ++++++++-------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/testng/internal/ExpectedExceptionsHolder.java b/src/main/java/org/testng/internal/ExpectedExceptionsHolder.java index 8fbd6fa..e497e3d 100755 --- a/src/main/java/org/testng/internal/ExpectedExceptionsHolder.java +++ b/src/main/java/org/testng/internal/ExpectedExceptionsHolder.java @@ -38,7 +38,7 @@ public class ExpectedExceptionsHolder { Class<?> realExceptionClass= ite.getClass(); for (Class<?> exception : expectedClasses) { - if (exception.isAssignableFrom(realExceptionClass)) { + if (exception.isAssignableFrom(realExceptionClass) && messageRegExpMatches(ite)) { return true; } } @@ -60,19 +60,19 @@ public class ExpectedExceptionsHolder { } } - public TestException buildTestException(Throwable ite) { - return new TestException("The exception was thrown with the wrong message:" + - " expected \"" + messageRegExp + "\"" + - " but got \"" + ite.getMessage() + "\"", ite); - } - - public TestException buildTestExceptionPluralize(Throwable ite) { - return new TestException("Expected exception of " + - getExpectedExceptionsPluralize() - + " but got " + ite, ite); + public TestException wrongException(Throwable ite) { + if (messageRegExpMatches(ite)) { + return new TestException("Expected exception of " + + getExpectedExceptionsPluralize() + + " but got " + ite, ite); + } else { + return new TestException("The exception was thrown with the wrong message:" + + " expected \"" + messageRegExp + "\"" + + " but got \"" + ite.getMessage() + "\"", ite); + } } - public TestException buildTestExceptionPluralize(ITestNGMethod testMethod) { + public TestException noException(ITestNGMethod testMethod) { if (expectedClasses == null || expectedClasses.length == 0) { return null; } diff --git a/src/main/java/org/testng/internal/Invoker.java b/src/main/java/org/testng/internal/Invoker.java index 00e696f..d44d6fe 100644 --- a/src/main/java/org/testng/internal/Invoker.java +++ b/src/main/java/org/testng/internal/Invoker.java @@ -3,14 +3,12 @@ package org.testng.internal; 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; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import org.testng.IClass; import org.testng.IConfigurable; @@ -1371,30 +1369,24 @@ public class Invoker implements IInvoker { if (ite != null) { // Invocation caused an exception, see if the method was annotated with @ExpectedException - if (expectedExceptionsHolder != null && expectedExceptionsHolder.isExpectedException(ite)) { - if (expectedExceptionsHolder.messageRegExpMatches(ite)) { - testResult.setStatus(ITestResult.SUCCESS); - status= ITestResult.SUCCESS; - } - else { - testResult.setThrowable(expectedExceptionsHolder.buildTestException(ite)); - status= ITestResult.FAILURE; - } + if (expectedExceptionsHolder != null && !expectedExceptionsHolder.isExpectedException(ite)) { + testResult.setThrowable(expectedExceptionsHolder.wrongException(ite)); + status= ITestResult.FAILURE; } else if (isSkipExceptionAndSkip(ite)){ status = ITestResult.SKIP; - } else if (expectedExceptionsHolder != null) { - testResult.setThrowable(expectedExceptionsHolder.buildTestExceptionPluralize(ite)); - status= ITestResult.FAILURE; - } else { + } else if (expectedExceptionsHolder == null) { handleException(ite, testMethod, testResult, failure.count++); handled = true; status = testResult.getStatus(); + } else { + testResult.setStatus(ITestResult.SUCCESS); + status= ITestResult.SUCCESS; } } // No exception thrown, make sure we weren't expecting one else if(status != ITestResult.SKIP && expectedExceptionsHolder != null) { - TestException exception = expectedExceptionsHolder.buildTestExceptionPluralize(testMethod); + TestException exception = expectedExceptionsHolder.noException(testMethod); if (exception != null) { testResult.setThrowable(exception); status= ITestResult.FAILURE; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

