You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2020/09/22 12:44:06 UTC

[maven-surefire] branch master updated: [SUREFIRE-1842] - NPE at end of successful test run

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a7b2e6  [SUREFIRE-1842] - NPE at end of successful test run
8a7b2e6 is described below

commit 8a7b2e6efcd5f62e900c41a4c64bcefa38729d49
Author: Michael Boyles <mi...@hotmail.co.uk>
AuthorDate: Mon Sep 21 17:41:19 2020 +0100

    [SUREFIRE-1842] - NPE at end of successful test run
---
 .../surefire/api/provider/ProviderParameters.java  |  2 +
 .../apache/maven/surefire/api/util/TestsToRun.java |  3 --
 .../api/booter/BaseProviderFactoryTest.java        | 55 +++++++++++++++++++
 surefire-providers/surefire-junit47/pom.xml        |  5 ++
 .../surefire/junitcore/JUnitCoreProvider.java      |  3 +-
 .../surefire/junitcore/JUnitCoreProviderTest.java  | 63 ++++++++++++++++++++++
 6 files changed, 127 insertions(+), 4 deletions(-)

diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
index 048622f..6fc54ee 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
@@ -30,6 +30,7 @@ import org.apache.maven.surefire.api.util.DirectoryScanner;
 import org.apache.maven.surefire.api.util.RunOrderCalculator;
 import org.apache.maven.surefire.api.util.ScanResult;
 
+import javax.annotation.Nullable;
 import java.util.List;
 import java.util.Map;
 
@@ -68,6 +69,7 @@ public interface ProviderParameters
      *
      * @return A RunOrderCalculator
      */
+    @Nullable
     RunOrderCalculator getRunOrderCalculator();
 
     /**
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/TestsToRun.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/TestsToRun.java
index 28736ef..bdf9e64 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/TestsToRun.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/TestsToRun.java
@@ -26,8 +26,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-
 import static java.lang.Math.max;
 
 /**
@@ -55,7 +53,6 @@ public class TestsToRun implements Iterable<Class<?>>
     }
 
     public static TestsToRun fromClass( Class<?> clazz )
-        throws TestSetFailedException
     {
         return new TestsToRun( Collections.<Class<?>>singleton( clazz ) );
     }
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/booter/BaseProviderFactoryTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/booter/BaseProviderFactoryTest.java
new file mode 100644
index 0000000..018e7f0
--- /dev/null
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/booter/BaseProviderFactoryTest.java
@@ -0,0 +1,55 @@
+package org.apache.maven.surefire.api.booter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Collections;
+
+import static org.junit.Assert.assertNull;
+
+/**
+ * @author Michael Boyles
+ */
+public class BaseProviderFactoryTest
+{
+    @Test
+    public void runOrderCalculatorIsNullIfNotSet()
+    {
+        BaseProviderFactory factory = new BaseProviderFactory( true );
+        factory.setDirectoryScannerParameters ( getDirectoryScannerParameters() );
+
+        assertNull( factory.getRunOrderCalculator() );
+    }
+
+    private DirectoryScannerParameters getDirectoryScannerParameters()
+    {
+        return new DirectoryScannerParameters(
+            new File( "/fake/file" ),
+            Collections.<String>emptyList(),
+            Collections.<String>emptyList(),
+            Collections.<String>emptyList(),
+            false,
+            "ALPHABETICAL"
+        );
+    }
+}
diff --git a/surefire-providers/surefire-junit47/pom.xml b/surefire-providers/surefire-junit47/pom.xml
index ddac05f..86f428f 100644
--- a/surefire-providers/surefire-junit47/pom.xml
+++ b/surefire-providers/surefire-junit47/pom.xml
@@ -54,6 +54,11 @@
             <version>1.0-1</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
index 6877b00..372351a 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
@@ -290,6 +290,7 @@ public class JUnitCoreProvider
     private TestsToRun scanClassPath()
     {
         TestsToRun scanned = scanResult.applyFilter( scannerFilter, testClassLoader );
-        return runOrderCalculator.orderTestClasses( scanned );
+        return runOrderCalculator == null
+            ? scanned : runOrderCalculator.orderTestClasses( scanned );
     }
 }
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderTest.java
new file mode 100644
index 0000000..34cf112
--- /dev/null
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderTest.java
@@ -0,0 +1,63 @@
+package org.apache.maven.surefire.junitcore;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.provider.ProviderParameters;
+import org.apache.maven.surefire.api.util.ScanResult;
+import org.apache.maven.surefire.api.util.ScannerFilter;
+import org.apache.maven.surefire.api.util.TestsToRun;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Iterator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Michael Boyles
+ */
+@RunWith( MockitoJUnitRunner.class )
+public class JUnitCoreProviderTest
+{
+    @Mock
+    private ProviderParameters providerParameters;
+    @Mock
+    private ScanResult scanResult;
+
+    @Test
+    public void doNotSortTestsIfNoRunOrderProvider()
+    {
+        Mockito.when( providerParameters.getScanResult() ).thenReturn( scanResult );
+        Mockito.when( scanResult.applyFilter( Mockito.any( ScannerFilter.class ), Mockito.any( ClassLoader.class ) ) )
+            .thenReturn( TestsToRun.fromClass( String.class ) );
+
+        JUnitCoreProvider provider = new JUnitCoreProvider( providerParameters );
+        Iterator<Class<?>> suites = provider.getSuites().iterator();
+
+        assertTrue( suites.hasNext() );
+        assertEquals( String.class, suites.next() );
+        assertFalse( suites.hasNext() );
+    }
+}