git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1471109 13f79535-47bb-0310-9956-ffa450edef68master
@@ -25,13 +25,11 @@ import java.io.StringWriter; | |||
import java.text.NumberFormat; | |||
import junit.framework.AssertionFailedError; | |||
import junit.framework.JUnit4TestCaseFacade; | |||
import junit.framework.Test; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StringUtils; | |||
import org.junit.Ignore; | |||
/** | |||
* Prints plain text output of the test to a specified Writer. | |||
@@ -274,15 +272,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter, IgnoredT | |||
public void testIgnored(Test test) { | |||
String message = null; | |||
if (test instanceof JUnit4TestCaseFacade) { | |||
JUnit4TestCaseFacade facade = (JUnit4TestCaseFacade) test; | |||
Ignore annotation = facade.getDescription().getAnnotation(Ignore.class); | |||
if (annotation != null && annotation.value().length() > 0) { | |||
message = annotation.value(); | |||
} | |||
} | |||
formatSkip(test, message); | |||
formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test)); | |||
} | |||
@@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs.optional.junit; | |||
import junit.framework.Test; | |||
import junit.framework.TestListener; | |||
import org.junit.runner.notification.Failure; | |||
/** | |||
* Provides the functionality for TestListeners to be able to be notified of | |||
@@ -35,7 +34,7 @@ public interface IgnoredTestListener extends TestListener { | |||
* should normally be typed to JUnit's {@link junit.framework.JUnit4TestCaseFacade} | |||
* so implementing classes should be able to get the details of the ignore by casting | |||
* the argument and retrieving the descriptor from the test. | |||
* @param test | |||
* @param test the details of the test and failure that have triggered this report. | |||
*/ | |||
void testIgnored(Test test); | |||
@@ -36,7 +36,6 @@ import java.util.Properties; | |||
import java.util.StringTokenizer; | |||
import java.util.Vector; | |||
import junit.framework.AssertionFailedError; | |||
import junit.framework.JUnit4TestAdapterCache; | |||
import junit.framework.Test; | |||
import junit.framework.TestFailure; | |||
import junit.framework.TestListener; | |||
@@ -402,6 +401,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||
} else { | |||
Class junit4TestAdapterClass = null; | |||
Class junit4TestAdapterCacheClass = null; | |||
boolean useSingleMethodAdapter = false; | |||
if (junit.framework.TestCase.class.isAssignableFrom(testClass)) { | |||
@@ -429,6 +429,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||
try { | |||
Class.forName("java.lang.annotation.Annotation"); | |||
junit4TestAdapterCacheClass = Class.forName("org.apache.tools.ant.taskdefs.optional.junit.CustomJUnit4TestAdapterCache"); | |||
if (loader == null) { | |||
junit4TestAdapterClass = | |||
Class.forName(JUNIT_4_TEST_ADAPTER); | |||
@@ -470,8 +471,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||
formalParams = new Class[] {Class.class, String[].class}; | |||
actualParams = new Object[] {testClass, methods}; | |||
} else { | |||
formalParams = new Class[] {Class.class, JUnit4TestAdapterCache.class}; | |||
actualParams = new Object[] {testClass, CustomJUnit4TestAdapterCache.getInstance()}; | |||
formalParams = new Class[] {Class.class, Class.forName("junit.framework.JUnit4TestAdapterCache")}; | |||
actualParams = new Object[] {testClass, junit4TestAdapterCacheClass.getMethod("getInstance").invoke(null)}; | |||
} | |||
suite = | |||
(Test) junit4TestAdapterClass | |||
@@ -18,7 +18,10 @@ | |||
package org.apache.tools.ant.taskdefs.optional.junit; | |||
import java.lang.annotation.Annotation; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Method; | |||
import junit.framework.Test; | |||
import junit.framework.TestCase; | |||
@@ -135,4 +138,42 @@ public class JUnitVersionHelper { | |||
return className; | |||
} | |||
public static String getIgnoreMessage(Test test) { | |||
String message = null; | |||
try { | |||
Class<?> junit4FacadeClass = Class.forName("junit.framework.JUnit4TestCaseFacade"); | |||
if (test != null && test.getClass().isAssignableFrom(junit4FacadeClass)) { | |||
//try and get the message coded as part of the ignore | |||
/* | |||
* org.junit.runner.Description contains a getAnnotation(Class) method... but this | |||
* wasn't in older versions of JUnit4 so we have to try and do this by reflection | |||
*/ | |||
Class<?> testClass = Class.forName(JUnitVersionHelper.getTestCaseClassName(test)); | |||
Method testMethod = testClass.getMethod(JUnitVersionHelper.getTestCaseName(test)); | |||
Class ignoreAnnotation = Class.forName("org.junit.Ignore"); | |||
Annotation annotation = testMethod.getAnnotation(ignoreAnnotation); | |||
if (annotation != null) { | |||
Method valueMethod = annotation.getClass().getMethod("value"); | |||
String value = (String) valueMethod.invoke(annotation); | |||
if (value != null && value.length() > 0) { | |||
message = value; | |||
} | |||
} | |||
} | |||
} catch (NoSuchMethodException e) { | |||
// silently ignore - we'll report a skip with no message | |||
} catch (ClassNotFoundException e) { | |||
// silently ignore - we'll report a skip with no message | |||
} catch (InvocationTargetException e) { | |||
// silently ignore - we'll report a skip with no message | |||
} catch (IllegalAccessException e) { | |||
// silently ignore - we'll report a skip with no message | |||
} | |||
return message; | |||
} | |||
} |
@@ -26,14 +26,11 @@ import java.text.NumberFormat; | |||
import java.util.Hashtable; | |||
import junit.framework.AssertionFailedError; | |||
import junit.framework.JUnit4TestCaseFacade; | |||
import junit.framework.Test; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StringUtils; | |||
import org.junit.Ignore; | |||
import org.junit.runner.notification.Failure; | |||
/** | |||
@@ -264,15 +261,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter, IgnoredT | |||
} | |||
public void testIgnored(Test test) { | |||
String message = null; | |||
if (test instanceof JUnit4TestCaseFacade) { | |||
JUnit4TestCaseFacade facade = (JUnit4TestCaseFacade) test; | |||
Ignore annotation = facade.getDescription().getAnnotation(Ignore.class); | |||
if (annotation != null && annotation.value().length() > 0) { | |||
message = annotation.value(); | |||
} | |||
} | |||
formatSkip(test, message); | |||
formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test)); | |||
} | |||
@@ -19,13 +19,9 @@ | |||
package org.apache.tools.ant.taskdefs.optional.junit; | |||
import junit.framework.AssertionFailedError; | |||
import junit.framework.JUnit4TestAdapterCache; | |||
import junit.framework.Test; | |||
import junit.framework.TestListener; | |||
import org.junit.internal.AssumptionViolatedException; | |||
import org.junit.runner.Description; | |||
import org.junit.runner.notification.Failure; | |||
public class TestListenerWrapper implements TestListener, IgnoredTestListener { | |||
@@ -23,7 +23,6 @@ import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.io.OutputStreamWriter; | |||
import java.io.Writer; | |||
import java.lang.reflect.Method; | |||
import java.net.InetAddress; | |||
import java.net.UnknownHostException; | |||
import java.util.Date; | |||
@@ -35,14 +34,12 @@ import javax.xml.parsers.DocumentBuilder; | |||
import javax.xml.parsers.DocumentBuilderFactory; | |||
import junit.framework.AssertionFailedError; | |||
import junit.framework.JUnit4TestCaseFacade; | |||
import junit.framework.Test; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.util.DOMElementWriter; | |||
import org.apache.tools.ant.util.DateUtils; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Ignore; | |||
import org.w3c.dom.Document; | |||
import org.w3c.dom.Element; | |||
import org.w3c.dom.Text; | |||
@@ -323,28 +320,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
} | |||
public void testIgnored(Test test) { | |||
String message = null; | |||
if (test != null && test instanceof JUnit4TestCaseFacade) { | |||
//try and get the message coded as part of the ignore | |||
/* | |||
* org.junit.runner.Description contains a getAnnotation(Class) method... but this | |||
* wasn't in older versions of JUnit4 so we have to try and do this by reflection | |||
*/ | |||
try { | |||
Class<?> testClass = Class.forName(JUnitVersionHelper.getTestCaseClassName(test)); | |||
Method testMethod = testClass.getMethod(JUnitVersionHelper.getTestCaseName(test)); | |||
Ignore annotation = testMethod.getAnnotation(Ignore.class); | |||
if (annotation != null && annotation.value().length() > 0) { | |||
message = annotation.value(); | |||
} | |||
} catch (NoSuchMethodException e) { | |||
// silently ignore - we'll report a skip with no message | |||
} catch (ClassNotFoundException e) { | |||
// silently ignore - we'll report a skip with no message | |||
} | |||
} | |||
formatSkip(test, message); | |||
formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test)); | |||
if (test != null) { | |||
ignoredTests.put(createDescription(test), test); | |||
} | |||
@@ -374,8 +350,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
} | |||
public void testAssumptionFailure(Test test, Throwable failure) { | |||
String message = failure.getMessage(); | |||
formatSkip(test, message); | |||
formatSkip(test, failure.getMessage()); | |||
skippedTests.put(createDescription(test), test); | |||
} | |||