maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tibordig...@apache.org
Subject maven-surefire git commit: [SUREFIRE-1187] JUnit4 Provider created unnecessary Runner instance
Date Fri, 23 Oct 2015 20:32:12 GMT
Repository: maven-surefire
Updated Branches:
  refs/heads/master ffadd7e72 -> d4135dd77


[SUREFIRE-1187] JUnit4 Provider created unnecessary Runner instance


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/d4135dd7
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/d4135dd7
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/d4135dd7

Branch: refs/heads/master
Commit: d4135dd7734428f879eed771ca60b7081c75acc5
Parents: ffadd7e
Author: tibordigana <tibor17@lycos.com>
Authored: Fri Oct 23 22:31:12 2015 +0200
Committer: tibordigana <tibor17@lycos.com>
Committed: Fri Oct 23 22:31:12 2015 +0200

----------------------------------------------------------------------
 .../maven/surefire/junit4/JUnit4Provider.java   | 15 ++++++------
 .../surefire/junit4/JUnit4ProviderTest.java     | 25 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4135dd7/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
index aae5fe3..493369d 100644
--- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
+++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
@@ -19,7 +19,6 @@ package org.apache.maven.surefire.junit4;
  * under the License.
  */
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
 
@@ -52,7 +51,6 @@ import org.junit.runner.Runner;
 import org.junit.runner.manipulation.Filter;
 import org.junit.runner.notification.StoppedByUserException;
 
-import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.createSuiteDescription;
 import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.cutTestClassAndMethod;
 import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.generateFailingTests;
 import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createDescription;
@@ -164,7 +162,7 @@ public class JUnit4Provider
         try
         {
             notifier.fireTestRunStarted( testsToRun.allowEagerReading()
-                                                ? createTestsDescription()
+                                                ? createTestsDescription( testsToRun )
                                                 : createDescription( UNDETERMINED_TESTS_DESCRIPTION
) );
 
             if ( commandsReader != null )
@@ -318,14 +316,15 @@ public class JUnit4Provider
         }
     }
 
-    private Description createTestsDescription()
+    static Description createTestsDescription( Iterable<Class<?>> classes )
     {
-        Collection<Class<?>> classes = new ArrayList<Class<?>>();
-        for ( Class<?> clazz : testsToRun )
+        // "null" string rather than null; otherwise NPE in junit:4.0
+        Description description = createDescription( "null" );
+        for ( Class<?> clazz : classes )
         {
-            classes.add( clazz );
+            description.addChild( createDescription( clazz.getName() ) );
         }
-        return createSuiteDescription( classes );
+        return description;
     }
 
     private static boolean isJUnit4UpgradeCheck()

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4135dd7/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
index 8f0356c..586c55e 100644
--- a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
+++ b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
@@ -22,9 +22,15 @@ package org.apache.maven.surefire.junit4;
 import junit.framework.TestCase;
 import org.apache.maven.surefire.booter.BaseProviderFactory;
 import org.apache.maven.surefire.testset.TestRequest;
+import org.junit.runner.Description;
 
+import java.util.Arrays;
 import java.util.HashMap;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.junit.runner.Description.createSuiteDescription;
+
 /**
  * @author Kristian Rosenvold
  */
@@ -44,4 +50,23 @@ public class JUnit4ProviderTest
         providerParameters.setTestRequest( new TestRequest( null, null, null ) );
         return new JUnit4Provider( providerParameters );
     }
+
+    public void testShouldCreateDescription()
+    {
+        class A {
+        }
+
+        class B {
+        }
+
+        Description d = JUnit4Provider.createTestsDescription( Arrays.<Class<?>>asList(
A.class, B.class ) );
+        assertThat( d, is( notNullValue() ) );
+        assertThat( d.getDisplayName(), not( isEmptyOrNullString() ) );
+        assertThat( d.getDisplayName(), is( "null" ) );
+        assertThat( d.getChildren(), hasSize( 2 ) );
+        Description a = createSuiteDescription( A.class );
+        Description b = createSuiteDescription( B.class );
+        assertThat( d.getChildren(), contains( a, b ) );
+    }
+
 }


Mime
View raw message