[testng] 81/160: Fix tests

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:24 UTC 2015


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 cda168c708e5d841b5cd0138b93d45f75b22178e
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Thu Jun 4 15:29:44 2015 +0200

    Fix tests
---
 .../internal/AbstractExpectedExceptionsHolder.java      | 14 +++++++++++---
 src/main/java/org/testng/internal/Invoker.java          | 17 +++++++++--------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/testng/internal/AbstractExpectedExceptionsHolder.java b/src/main/java/org/testng/internal/AbstractExpectedExceptionsHolder.java
index b2e68f7..e5ab7b0 100644
--- a/src/main/java/org/testng/internal/AbstractExpectedExceptionsHolder.java
+++ b/src/main/java/org/testng/internal/AbstractExpectedExceptionsHolder.java
@@ -43,7 +43,7 @@ public abstract class AbstractExpectedExceptionsHolder {
    * expected exceptions
    */
   public boolean isExpectedException(Throwable ite) {
-    if (expectedClasses == null) {
+    if (!hasExpectectedClasses()) {
       return false;
     }
 
@@ -64,7 +64,11 @@ public abstract class AbstractExpectedExceptionsHolder {
     return false;
   }
 
-  public TestException wrongException(Throwable ite) {
+  public Throwable wrongException(Throwable ite) {
+    if (!hasExpectectedClasses()) {
+      return ite;
+    }
+
     if (isExceptionMatches(ite)) {
       return new TestException("Expected exception of " +
                                getExpectedExceptionsPluralize()
@@ -77,13 +81,17 @@ public abstract class AbstractExpectedExceptionsHolder {
   protected abstract String getWrongExceptionMessage(Throwable ite);
 
   public TestException noException(ITestNGMethod testMethod) {
-    if (expectedClasses == null || expectedClasses.length == 0) {
+    if (!hasExpectectedClasses()) {
       return null;
     }
     return new TestException("Method " + testMethod + " should have thrown an exception of "
                              + getExpectedExceptionsPluralize());
   }
 
+  private boolean hasExpectectedClasses() {
+    return expectedClasses != null && expectedClasses.length > 0;
+  }
+
   private String getExpectedExceptionsPluralize() {
     StringBuilder sb = new StringBuilder();
     if (expectedClasses.length > 1) {
diff --git a/src/main/java/org/testng/internal/Invoker.java b/src/main/java/org/testng/internal/Invoker.java
index 109b45e..921daaf 100644
--- a/src/main/java/org/testng/internal/Invoker.java
+++ b/src/main/java/org/testng/internal/Invoker.java
@@ -1371,16 +1371,18 @@ public class Invoker implements IInvoker {
           status = ITestResult.SKIP;
         }
         //  Invocation caused an exception, see if the method was annotated with @ExpectedException
-        else if (expectedExceptionsHolder != null && !expectedExceptionsHolder.isExpectedException(ite)) {
-          testResult.setThrowable(expectedExceptionsHolder.wrongException(ite));
-          status= ITestResult.FAILURE;
-        } else if (expectedExceptionsHolder == null) {
+        else if (expectedExceptionsHolder != null) {
+          if (expectedExceptionsHolder.isExpectedException(ite)) {
+            testResult.setStatus(ITestResult.SUCCESS);
+            status = ITestResult.SUCCESS;
+          } else {
+            testResult.setThrowable(expectedExceptionsHolder.wrongException(ite));
+            status= ITestResult.FAILURE;
+          }
+        } else {
           handleException(ite, testMethod, testResult, failure.count++);
           handled = true;
           status = testResult.getStatus();
-        } else {
-          testResult.setStatus(ITestResult.SUCCESS);
-          status= ITestResult.SUCCESS;
         }
       }
 
@@ -1404,7 +1406,6 @@ public class Invoker implements IInvoker {
         testResult.setStatus(status);
         if (status == ITestResult.FAILURE && !handled) {
           handleException(ite, testMethod, testResult, failure.count++);
-          testResult.setStatus(status);
         }
       }
       if (collectResults) {

-- 
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