From b8e3f831d63cc75c059e4b47f6f7eb3d03bfd100 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 14 Oct 2008 16:05:17 +0000 Subject: [PATCH] subclasses of AssertionErrors are caused by test failures, not errors. PR 45028. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@704571 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 6 ++++++ .../taskdefs/optional/junit/JUnitTestRunner.java | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 0598c22cc..ea770fbda 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -247,6 +247,12 @@ Fixed bugs: * MailLogger could cause a NullPointerException. Bugzilla Report 44009. + * didn't recognize failed assertions as failures if they + caused subclasses of AssertionError to be thrown (like + org.junit.ComparisonFailure that is thrown when assertEquals + fails). + Bugzilla Report 45028. + Other changes: -------------- 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 75d2d3091..e766c1e9a 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 @@ -976,7 +976,7 @@ 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 && t.getClass().getName().equals("java.lang.AssertionError")) { + } else if (junit4 && isAssertionError(t.getClass())) { // Not strictly necessary but probably desirable. // JUnit 4-specific test GUIs will show just "failures". // But Ant's output shows "failures" vs. "errors". @@ -1035,7 +1035,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR while (e.hasMoreElements()) { Throwable t = ((TestFailure) e.nextElement()).thrownException(); if (t instanceof AssertionFailedError - || t.getClass().getName().equals("java.lang.AssertionError")) { + || isAssertionError(t.getClass())) { failures++; } else { errors++; @@ -1044,4 +1044,14 @@ 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