ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcla...@apache.org
Subject svn commit: r1471109 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/
Date Tue, 23 Apr 2013 19:29:27 GMT
Author: mclarke
Date: Tue Apr 23 19:29:27 2013
New Revision: 1471109

URL: http://svn.apache.org/r1471109
Log:
Re-introduce ability to build JUnit task for only JUnit3

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/IgnoredTestListener.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestListenerWrapper.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
Tue Apr 23 19:29:27 2013
@@ -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 i
 
 
     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));
     }
 
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/IgnoredTestListener.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/IgnoredTestListener.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/IgnoredTestListener.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/IgnoredTestListener.java
Tue Apr 23 19:29:27 2013
@@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs.op
 
 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 ext
      * 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);
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
Tue Apr 23 19:29:27 2013
@@ -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 
 
                 } 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 
 
                     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 
                             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

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
Tue Apr 23 19:29:27 2013
@@ -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;
+
+    }
+
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
Tue Apr 23 19:29:27 2013
@@ -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 i
     }
 
     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));
     }
 
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestListenerWrapper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestListenerWrapper.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestListenerWrapper.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestListenerWrapper.java
Tue Apr 23 19:29:27 2013
@@ -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 {
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java?rev=1471109&r1=1471108&r2=1471109&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
Tue Apr 23 19:29:27 2013
@@ -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 imp
     }
 
     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 imp
     }
 
     public void testAssumptionFailure(Test test, Throwable failure) {
-        String message = failure.getMessage();
-        formatSkip(test, message);
+        formatSkip(test, failure.getMessage());
         skippedTests.put(createDescription(test), test);
 
     }



Mime
View raw message