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 2019/02/16 11:38:57 UTC

[maven-surefire] 02/02: [SUREFIRE-1585] Align JUnit Platform version at runtime

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

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

commit 36f777ca1a66a07f1dc2c1ae799f32bd3f969e62
Author: tibordigana <ti...@apache.org>
AuthorDate: Sat Feb 16 12:38:45 2019 +0100

    [SUREFIRE-1585] Align JUnit Platform version at runtime
---
 .../plugin/surefire/AbstractSurefireMojo.java      | 14 ++--
 .../plugin/surefire/AbstractSurefireMojoTest.java  | 87 ++++++++++++----------
 2 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 90fc075..7ae7d0f 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -480,12 +480,13 @@ public abstract class AbstractSurefireMojo
     private String junitArtifactName;
 
     /**
-     * Allows you to specify the name of the JUnit Platform artifact.
-     * If not set, {@code org.junit.platform:junit-platform-engine} will be used.
+     * Allows you to select the name of JUnit5 engine.<br>
+     * If not set, all engines on classpath are used. In normal circumstances the provider is able to
+     * work with multiple engines and no selection is needed to make.
      *
      * @since 2.22.0
      */
-    @Parameter( property = "junitPlatformArtifactName", defaultValue = "org.junit.platform:junit-platform-engine" )
+    @Parameter( property = "junitPlatformArtifactName", defaultValue = "org.junit.platform:junit-platform-commons" )
     private String junitPlatformArtifactName;
 
     /**
@@ -2677,7 +2678,7 @@ public abstract class AbstractSurefireMojo
                                                             + "is picking up an old junit version" );
                     }
                     throw new MojoFailureException( "groups/excludedGroups require TestNG, JUnit48+ or JUnit 5 "
-                            + "on project test classpath" );
+                            + "(a specific engine required on classpath) on project test classpath" );
                 }
             }
 
@@ -2917,7 +2918,6 @@ public abstract class AbstractSurefireMojo
             Map<String, Artifact> providerArtifacts =
                     dependencyResolver.getProviderClasspathAsMap( "surefire-junit-platform", surefireVersion );
             Map<String, Artifact> testDependencies = testClasspath.getTestDependencies();
-            // pozri hore ten parameter pre junit-platform-engine premenuj hodnotu na junit-platform-commons
             if ( hasDependencyPlatformEngine( testDependencies ) )
             {
                 String filterTestDependency = "org.junit.platform:junit-platform-engine";
@@ -2939,10 +2939,6 @@ public abstract class AbstractSurefireMojo
                 addEngineByApi( api, engineGroupId, engineArtifactId, providerArtifacts, testDependencies );
                 alignVersions( version, providerArtifacts, testDependencies );
             }
-            /*else if ( hasDependencyJUnit4( testDependencies ) )
-            {
-                addEngineByApi( "junit:junit", "junit", "junit", providerArtifacts, testDependencies );
-            }*/
             return new LinkedHashSet<>( providerArtifacts.values() );
         }
 
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index 016eef8..6e7f6c7 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -36,7 +36,6 @@ import org.apache.maven.surefire.booter.Classpath;
 import org.apache.maven.surefire.booter.StartupConfiguration;
 import org.apache.maven.surefire.suite.RunResult;
 import org.codehaus.plexus.logging.Logger;
-import org.fest.assertions.MapAssert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
@@ -500,11 +499,9 @@ public class AbstractSurefireMojoTest
                 .containsOnly( expectedProvider, expectedCommonJava5, expectedLauncher, expectedApiguardian,
                         expectedJUnit5Engine, expectedOpentest4j, expectedPlatformCommons );
 
-        Artifact expectedJUnit = new DefaultArtifact( "junit", "junit",
-                createFromVersion( "4.12" ), null, "jar", null, mock( ArtifactHandler.class ) );
         assertThat( testClasspathWrapper.getTestDependencies() )
                 .hasSize( 1 )
-                .includes( entry( "junit:junit", expectedJUnit ) );
+                .includes( entry( "junit:junit", testClasspathJUnit ) );
     }
 
     @Test
@@ -513,16 +510,16 @@ public class AbstractSurefireMojoTest
         final VersionRange surefireVersion = createFromVersion( "1" );
 
         Artifact junitPlatformArtifact = new DefaultArtifact( "org.apache.maven.surefire",
-                "surefire-junit-platform", surefireVersion, null, "jar", "", mock( ArtifactHandler.class ) );
+                "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
-                createFromVersion( "1.0" ), null, "jar", "", null );
-
-        final Artifact testClasspathApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
-                createFromVersion( "1.0.0" ), null, "jar", "", null );
+                createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathCommons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
-                createFromVersion( "1.4.0" ), null, "jar", "", mock( ArtifactHandler.class ) );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+
+        final Artifact testClasspathApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
+                createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         Iterable<Artifact> testArtifacts =
                 asList( testClasspathSomeTestArtifact, testClasspathApiguardian, testClasspathCommons );
@@ -535,14 +532,14 @@ public class AbstractSurefireMojoTest
                 new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
 
         Artifact forkedBooter = new DefaultArtifact( "org.apache.maven.surefire",
-                "surefire-booter", surefireVersion, null, "jar", "", null );
+                "surefire-booter", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
 
         mojo.setPluginArtifactMap( singletonMap( "org.apache.maven.surefire:surefire-booter", forkedBooter ) );
         mojo.setRemoteRepositories( Collections.<ArtifactRepository>emptyList() );
         mojo.setProjectRemoteRepositories( Collections.<ArtifactRepository>emptyList() );
         RepositorySystem repositorySystem = mock( RepositorySystem.class );
         final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
-                "surefire-junit-platform", surefireVersion, null, "jar", "", null );
+                "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
         when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer<Artifact>()
         {
             @Override
@@ -594,16 +591,22 @@ public class AbstractSurefireMojoTest
         Set<Artifact> resolvedProviderArtifacts = prov.getProviderClasspath();
 
         Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
-                surefireVersion, null, "jar", "", null );
+                surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
-                createFromVersion( "1.4.0" ), null, "jar", "", null );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact testClasspathJUnit5 = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
-                createFromVersion( "1.4.0" ), null, "jar", "", null );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact testClasspathOpentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
-                createFromVersion( "1.1.1" ), null, "jar", "", null );
+                createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
         assertThat( resolvedProviderArtifacts )
                 .hasSize( 5 )
                 .containsOnly( surefireProvider, java5, launcher, testClasspathJUnit5, testClasspathOpentest4j );
+
+        assertThat( testClasspathWrapper.getTestDependencies() )
+                .hasSize( 3 )
+                .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+                        entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
+                        entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ) );
     }
 
     @Test
@@ -612,22 +615,22 @@ public class AbstractSurefireMojoTest
         final VersionRange surefireVersion = createFromVersion( "1" );
 
         Artifact junitPlatformArtifact = new DefaultArtifact( "org.apache.maven.surefire",
-                "surefire-junit-platform", surefireVersion, null, "jar", "", mock( ArtifactHandler.class ) );
+                "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
-                createFromVersion( "1.0" ), null, "jar", "", null );
+                createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathJUnit5 = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
-                createFromVersion( "1.4.0" ), null, "jar", "", null );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
-                createFromVersion( "1.0.0" ), null, "jar", "", null );
+                createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathCommons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
-                createFromVersion( "1.4.0" ), null, "jar", "", mock( ArtifactHandler.class ) );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         final Artifact testClasspathOpentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
-                createFromVersion( "1.1.1" ), null, "jar", "", null );
+                createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         Iterable<Artifact> testArtifacts = asList( testClasspathSomeTestArtifact, testClasspathJUnit5,
                 testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
@@ -640,14 +643,14 @@ public class AbstractSurefireMojoTest
                 new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
 
         Artifact forkedBooter = new DefaultArtifact( "org.apache.maven.surefire",
-                "surefire-booter", surefireVersion, null, "jar", "", null );
+                "surefire-booter", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
 
         mojo.setPluginArtifactMap( singletonMap( "org.apache.maven.surefire:surefire-booter", forkedBooter ) );
         mojo.setRemoteRepositories( Collections.<ArtifactRepository>emptyList() );
         mojo.setProjectRemoteRepositories( Collections.<ArtifactRepository>emptyList() );
         RepositorySystem repositorySystem = mock( RepositorySystem.class );
         final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
-                "surefire-junit-platform", surefireVersion, null, "jar", "", null );
+                "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
         when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer<Artifact>()
         {
             @Override
@@ -701,12 +704,20 @@ public class AbstractSurefireMojoTest
         Set<Artifact> resolvedProviderArtifacts = prov.getProviderClasspath();
 
         Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
-                surefireVersion, null, "jar", "", null );
+                surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
-                createFromVersion( "1.4.0" ), null, "jar", "", null );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         assertThat( resolvedProviderArtifacts )
                 .hasSize( 3 )
                 .containsOnly( surefireProvider, java5, launcher );
+
+        assertThat( testClasspathWrapper.getTestDependencies() )
+                .hasSize( 5 )
+                .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+                        entry( "org.junit.platform:junit-platform-engine", testClasspathJUnit5 ),
+                        entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
+                        entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
+                        entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
     }
 
     private static ArtifactResolutionResult createJUnitPlatformLauncherResolutionResult(
@@ -715,7 +726,7 @@ public class AbstractSurefireMojoTest
         ArtifactResolutionResult launcherResolutionResult = mock( ArtifactResolutionResult.class );
         Set<Artifact> resolvedLauncherArtifacts = new HashSet<>();
         Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
-                commons.getVersionRange(), null, "jar", "", null );
+                commons.getVersionRange(), null, "jar", null, mock( ArtifactHandler.class ) );
         resolvedLauncherArtifacts.add( launcher );
         resolvedLauncherArtifacts.add( apiguardian );
         resolvedLauncherArtifacts.add( junit5Engine );
@@ -730,13 +741,13 @@ public class AbstractSurefireMojoTest
     private static ArtifactResolutionResult createExpectedJUnitPlatformLauncherResolutionResult()
     {
         Artifact engine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
-                createFromVersion( "1.4.0" ), null, "jar", "", mock( ArtifactHandler.class ) );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact commons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
-                createFromVersion( "1.4.0" ), null, "jar", "", mock( ArtifactHandler.class ) );
+                createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact apiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
-                createFromVersion( "1.0.0" ), null, "jar", "", null );
+                createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
-                createFromVersion( "1.1.1" ), null, "jar", "", mock( ArtifactHandler.class ) );
+                createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
         return createJUnitPlatformLauncherResolutionResult( engine, apiguardian, commons, opentest4j );
     }
 
@@ -762,19 +773,19 @@ public class AbstractSurefireMojoTest
         ArtifactResolutionResult surefirePlatformResolutionResult = mock( ArtifactResolutionResult.class );
 
         Artifact provider = new DefaultArtifact( "org.apache.maven.surefire", "surefire-junit-platform",
-                surefireVersion, null, "jar", "", null );
+                surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
-                surefireVersion, null, "jar", "", null );
+                surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
-                createFromVersion( "1.3.2" ), null, "jar", "", null );
+                createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact apiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
-                createFromVersion( "1.0.0" ), null, "jar", "", null );
+                createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact engine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
-                createFromVersion( "1.3.2" ), null, "jar", "", null );
+                createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact commons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
-                createFromVersion( "1.3.2" ), null, "jar", "", null );
+                createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
         Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
-                createFromVersion( "1.1.1" ), null, "jar", "", null );
+                createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
 
         Set<Artifact> providerArtifacts = new HashSet<>();
         providerArtifacts.add( provider );