From b9782aa6bcdc139d41eae6a4d25435dacefee230 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 9 Jun 2015 17:24:17 +0200 Subject: [PATCH] Handle junit's AssertionError in integration tests --- .../igniterealtime/smack/inttest/FailedTest.java | 4 ++-- .../inttest/SmackIntegrationTestFramework.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/FailedTest.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/FailedTest.java index 4085e3f3e..2d5c64696 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/FailedTest.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/FailedTest.java @@ -21,9 +21,9 @@ import java.util.List; public class FailedTest extends TestResult { - public final Exception failureReason; + public final Throwable failureReason; - public FailedTest(Method testMethod, long startTime, long endTime, List logMessages, Exception failureReason) { + public FailedTest(Method testMethod, long startTime, long endTime, List logMessages, Throwable failureReason) { super(testMethod, startTime, endTime, logMessages); this.failureReason = failureReason; } diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java index 3157419c9..ae51e2f4b 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java @@ -102,7 +102,7 @@ public class SmackIntegrationTestFramework { final Method method = failedTest.testMethod; final String className = method.getDeclaringClass().getName(); final String methodName = method.getName(); - final Exception cause = failedTest.failureReason; + final Throwable cause = failedTest.failureReason; LOGGER.severe(className + CLASS_METHOD_SEP + methodName + " failed: " + cause); } System.exit(2); @@ -380,10 +380,17 @@ public class SmackIntegrationTestFramework { null, (TestNotPossibleException) cause)); continue; } - Exception nonFatalException = throwFatalException(cause); + Throwable nonFatalFailureReason; + // junit assert's throw an AssertionError if they fail, those should not be + // thrown up, as it would be done by throwFatalException() + if (cause instanceof AssertionError) { + nonFatalFailureReason = cause; + } else { + nonFatalFailureReason = throwFatalException(cause); + } // An integration test failed testRunResult.failedIntegrationTests.add(new FailedTest(testMethod, testStart, testEnd, null, - nonFatalException)); + nonFatalFailureReason)); LOGGER.log(Level.SEVERE, testPrefix + "Failed", e); } catch (IllegalArgumentException | IllegalAccessException e) {