From 8c3c62ba7c84790a1de9509012aac980e41de3ef Mon Sep 17 00:00:00 2001
From: Jacobus Martinus Kruithof
Date: Sun, 1 Feb 2009 22:30:48 +0000
Subject: [PATCH] Do not filter out AssertionError bugzilla 45631. Also some
corrections and still avoid inclusion of the AssertionError "Caused by" line
as originally present when converting to AssertionFailedError.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@739873 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/OptionalTasks/junit.html | 4 +-
.../optional/junit/JUnitTestRunner.java | 43 +++++--------------
2 files changed, 14 insertions(+), 33 deletions(-)
diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html
index 4af2ef929..d120fd4d0 100644
--- a/docs/manual/OptionalTasks/junit.html
+++ b/docs/manual/OptionalTasks/junit.html
@@ -245,7 +245,9 @@ that begin with the following string patterns:
"junit.textui.TestRunner"
"java.lang.reflect.Method.invoke("
"sun.reflect."
- "org.apache.tools.ant."
+ "org.apache.tools.ant."
+ "org.junit."
+ "junit.framework.JUnit4TestAdapter"
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
index e766c1e9a..490f4c4de 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
@@ -111,8 +111,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
// JUnit 4 support:
"org.junit.",
"junit.framework.JUnit4TestAdapter",
- // See wrapListener for reason:
- "Caused by: java.lang.AssertionError",
" more",
};
@@ -643,7 +641,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
/** {@inheritDoc}. */
public void addFormatter(JUnitTaskMirror.JUnitResultFormatterMirror f) {
- formatters.addElement((JUnitResultFormatter) f);
+ formatters.addElement(f);
}
/**
@@ -976,25 +974,16 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
// even in the JUnit 3 adapter.
// So we need to help it a bit to retain compatibility for JUnit 3 tests.
testListener.addFailure(test, (AssertionFailedError) t);
- } else if (junit4 && isAssertionError(t.getClass())) {
+ } else if (junit4 && t instanceof AssertionError) {
// Not strictly necessary but probably desirable.
// JUnit 4-specific test GUIs will show just "failures".
// But Ant's output shows "failures" vs. "errors".
// We would prefer to show "failure" for things that logically are.
- try {
- String msg = t.getMessage();
- AssertionFailedError failure = msg != null
- ? new AssertionFailedError(msg) : new AssertionFailedError();
- // To compile on pre-JDK 4 (even though this should always succeed):
- Method initCause = Throwable.class.getMethod(
- "initCause", new Class[] {Throwable.class});
- initCause.invoke(failure, new Object[] {t});
- testListener.addFailure(test, failure);
- } catch (Exception e) {
- // Rats.
- e.printStackTrace(); // should not happen
- testListener.addError(test, t);
- }
+ String msg = t.getMessage();
+ AssertionFailedError failure = msg != null
+ ? new AssertionFailedError(msg) : new AssertionFailedError();
+ failure.setStackTrace(t.getStackTrace());
+ testListener.addFailure(test, failure);
} else {
testListener.addError(test, t);
}
@@ -1023,19 +1012,19 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* since the adapter claims that all failures are errors.
* @since Ant 1.7
*/
- private int[] findJUnit4FailureErrorCount(TestResult res) {
+ private int[] findJUnit4FailureErrorCount(TestResult result) {
int failures = 0;
int errors = 0;
- Enumeration e = res.failures();
+ Enumeration e = result.failures();
while (e.hasMoreElements()) {
e.nextElement();
failures++;
}
- e = res.errors();
+ e = result.errors();
while (e.hasMoreElements()) {
Throwable t = ((TestFailure) e.nextElement()).thrownException();
if (t instanceof AssertionFailedError
- || isAssertionError(t.getClass())) {
+ || t instanceof AssertionError) {
failures++;
} else {
errors++;
@@ -1044,14 +1033,4 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
return new int[] {failures, errors};
}
- private static boolean isAssertionError(Class clazz) {
- while (clazz != null) {
- if (clazz.getName().equals("java.lang.AssertionError")) {
- return true;
- }
- clazz = clazz.getSuperclass();
- }
- return false;
- }
-
} // JUnitTestRunner