From commits-return-76403-archive-asf-public=cust-asf.ponee.io@maven.apache.org Fri Oct 5 12:36:24 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id D5338180677 for ; Fri, 5 Oct 2018 12:36:21 +0200 (CEST) Received: (qmail 81280 invoked by uid 500); 5 Oct 2018 10:36:20 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 81271 invoked by uid 99); 5 Oct 2018 10:36:20 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Oct 2018 10:36:20 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 27F7985BA2; Fri, 5 Oct 2018 10:36:20 +0000 (UTC) Date: Fri, 05 Oct 2018 10:36:20 +0000 To: "commits@maven.apache.org" Subject: [maven-surefire] 01/01: [SUREFIRE-1564] Can't override platform version through project/plugin dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: tibordigana@apache.org In-Reply-To: <153873577935.8950.14371234972090447881@gitbox.apache.org> References: <153873577935.8950.14371234972090447881@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: maven-surefire X-Git-Refname: refs/heads/1564_2 X-Git-Reftype: branch X-Git-Rev: 1fecdadc67dfb7ddac12fd0b64b5f59cb6913bf9 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20181005103620.27F7985BA2@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch 1564_2 in repository https://gitbox.apache.org/repos/asf/maven-surefire.git commit 1fecdadc67dfb7ddac12fd0b64b5f59cb6913bf9 Author: Christian Stein AuthorDate: Fri Sep 14 05:51:56 2018 +0200 [SUREFIRE-1564] Can't override platform version through project/plugin dependencies --- .../plugin/surefire/AbstractSurefireMojo.java | 173 +++++++++------------ .../maven/plugin/surefire/ClasspathCache.java | 17 ++ .../apache/maven/plugin/surefire/ProviderInfo.java | 10 +- .../surefire/SurefireDependencyResolver.java | 64 ++++---- .../maven/plugin/surefire/TestClassPath.java | 115 ++++++++++++++ .../AbstractSurefireMojoJava7PlusTest.java | 74 +++++++-- .../plugin/surefire/AbstractSurefireMojoTest.java | 92 ++++++++--- .../maven/surefire/its/JUnitPlatformEnginesIT.java | 160 +++++++++++++++++++ .../apache/maven/surefire/its/JUnitPlatformIT.java | 48 +++--- .../apache/maven/surefire/its/fixture/IsRegex.java | 100 ++++++++++++ .../surefire/its/fixture/OutputValidator.java | 29 ++-- .../Surefire1082ParallelJUnitParameterizedIT.java | 61 +------- .../test/resources/junit-platform-1.1.1/pom.xml | 60 ------- .../JUnitPlatform_1_1_1_Test.java | 37 ----- .../test/resources/junit-platform-1.2.0/pom.xml | 60 ------- .../JUnitPlatform_1_2_0_Test.java | 37 ----- .../pom.xml | 17 +- .../java/junitplatform/JUnitPlatformTest.java} | 5 +- surefire-providers/surefire-junit-platform/pom.xml | 4 +- .../junitplatform/RunListenerAdapterTest.java | 5 +- .../junitplatform/TestMethodFilterTest.java | 5 +- 21 files changed, 693 insertions(+), 480 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 fa4f257..1a52dab 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 @@ -1712,64 +1712,59 @@ public abstract class AbstractSurefireMojo private StartupConfiguration createStartupConfiguration( @Nonnull ProviderInfo provider, boolean isInprocess, @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull DefaultScanResult scanResult ) - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException { try { - // cache the provider lookup - String providerName = provider.getProviderName(); - Classpath providerClasspath = ClasspathCache.getCachedClassPath( providerName ); - if ( providerClasspath == null ) - { - // todo: 100 milli seconds, try to fetch List within classpath asynchronously - providerClasspath = provider.getProviderClasspath(); - ClasspathCache.setCachedClasspath( providerName, providerClasspath ); - } - Artifact surefireArtifact = getCommonArtifact(); - Classpath inprocClassPath = - providerClasspath.addClassPathElementUrl( surefireArtifact.getFile().getAbsolutePath() ) - .addClassPathElementUrl( getApiArtifact().getFile().getAbsolutePath() ); - File moduleDescriptor = getModuleDescriptor(); - + Set providerArtifacts = provider.getProviderClasspath(); + String providerName = provider.getProviderName(); if ( moduleDescriptor.exists() && !isInprocess ) { - return newStartupConfigForModularClasspath( classLoaderConfiguration, providerClasspath, providerName, + return newStartupConfigWithModularPath( classLoaderConfiguration, providerArtifacts, providerName, moduleDescriptor, scanResult ); } else { - return newStartupConfigForNonModularClasspath( classLoaderConfiguration, providerClasspath, - inprocClassPath, providerName ); + return newStartupConfigWithClasspath( classLoaderConfiguration, providerArtifacts, providerName ); } } catch ( AbstractArtifactResolutionException e ) { throw new MojoExecutionException( "Unable to generate classpath: " + e, e ); } - catch ( InvalidVersionSpecificationException e ) - { - throw new MojoExecutionException( "Unable to generate classpath: " + e, e ); - } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } - private StartupConfiguration newStartupConfigForNonModularClasspath( - @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Classpath providerClasspath, - @Nonnull Classpath inprocClasspath, @Nonnull String providerName ) - throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException, - AbstractArtifactResolutionException + private StartupConfiguration newStartupConfigWithClasspath( + @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Set providerArtifacts, + @Nonnull String providerName ) { - Classpath testClasspath = generateTestClasspath(); + TestClassPath testClasspathWrapper = generateTestClasspath(); + Classpath testClasspath = testClasspathWrapper.toClasspath(); + + testClasspathWrapper.avoidArtifactDuplicates( providerArtifacts ); + + Classpath providerClasspath = ClasspathCache.getCachedClassPath( providerName ); + if ( providerClasspath == null ) + { + providerClasspath = ClasspathCache.setCachedClasspath( providerName, providerArtifacts ); + } getConsoleLogger().debug( testClasspath.getLogMessage( "test classpath:" ) ); getConsoleLogger().debug( providerClasspath.getLogMessage( "provider classpath:" ) ); getConsoleLogger().debug( testClasspath.getCompactLogMessage( "test(compact) classpath:" ) ); getConsoleLogger().debug( providerClasspath.getCompactLogMessage( "provider(compact) classpath:" ) ); + String surefireCommonArtifactPath = getCommonArtifact().getFile().getAbsolutePath(); // todo: why added? + String surefireApiArtifactPath = getApiArtifact().getFile().getAbsolutePath(); + // todo: surefireApiArtifactPath is always in every provider - why added here? + Classpath inprocClasspath = providerClasspath.addClassPathElementUrl( surefireCommonArtifactPath ) + .addClassPathElementUrl( surefireApiArtifactPath ); + ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( testClasspath, providerClasspath, inprocClasspath, effectiveIsEnableAssertions(), isChildDelegation() ); @@ -1782,18 +1777,28 @@ public abstract class AbstractSurefireMojo return new LocationManager(); } - private StartupConfiguration newStartupConfigForModularClasspath( - @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Classpath providerClasspath, + private StartupConfiguration newStartupConfigWithModularPath( + @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Set providerArtifacts, @Nonnull String providerName, @Nonnull File moduleDescriptor, @Nonnull DefaultScanResult scanResult ) - throws MojoExecutionException, MojoFailureException, InvalidVersionSpecificationException, - AbstractArtifactResolutionException, IOException + throws IOException { - ResolvePathsRequest req = ResolvePathsRequest.withStrings( generateTestClasspath().getClassPath() ) + TestClassPath testClasspathWrapper = generateTestClasspath(); + Classpath testClasspath = testClasspathWrapper.toClasspath(); + + testClasspathWrapper.avoidArtifactDuplicates( providerArtifacts ); + + Classpath providerClasspath = ClasspathCache.getCachedClassPath( providerName ); + if ( providerClasspath == null ) + { + providerClasspath = ClasspathCache.setCachedClasspath( providerName, providerArtifacts ); + } + + ResolvePathsRequest req = ResolvePathsRequest.ofStrings( testClasspath.getClassPath() ) .setMainModuleDescriptor( moduleDescriptor.getAbsolutePath() ); ResolvePathsResult result = ( (LocationManager) getLocationManager() ).resolvePaths( req ); - Classpath testClasspath = new Classpath( result.getClasspathElements() ); + testClasspath = new Classpath( result.getClasspathElements() ); Classpath testModulepath = new Classpath( result.getModulepathElements().keySet() ); SortedSet packages = new TreeSet(); @@ -2094,13 +2099,13 @@ public abstract class AbstractSurefireMojo } private InPluginVMSurefireStarter createInprocessStarter( @Nonnull ProviderInfo provider, - @Nonnull ClassLoaderConfiguration classLoaderConfiguration, + @Nonnull ClassLoaderConfiguration classLoaderConfig, @Nonnull RunOrderParameters runOrderParameters, @Nonnull DefaultScanResult scanResult ) throws MojoExecutionException, MojoFailureException { StartupConfiguration startupConfiguration = - createStartupConfiguration( provider, true, classLoaderConfiguration, scanResult ); + createStartupConfiguration( provider, true, classLoaderConfig, scanResult ); String configChecksum = getConfigChecksum(); StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration( configChecksum, false ); ProviderConfiguration providerConfiguration = createProviderConfiguration( runOrderParameters ); @@ -2425,25 +2430,12 @@ public abstract class AbstractSurefireMojo } /** - * Generate the test classpath. + * Generates the test classpath. * - * @return List containing the classpath elements - * @throws InvalidVersionSpecificationException - * when it happens - * @throws MojoFailureException when it happens - * @throws ArtifactNotFoundException when it happens - * @throws ArtifactResolutionException when it happens + * @return the classpath elements */ - private Classpath generateTestClasspath() - throws InvalidVersionSpecificationException, MojoFailureException, ArtifactResolutionException, - ArtifactNotFoundException, MojoExecutionException + private TestClassPath generateTestClasspath() { - List classpath = new ArrayList( 2 + getProject().getArtifacts().size() ); - - classpath.add( getTestClassesDirectory().getAbsolutePath() ); - - classpath.add( getClassesDirectory().getAbsolutePath() ); - @SuppressWarnings( "unchecked" ) Set classpathArtifacts = getProject().getArtifacts(); if ( getClasspathDependencyScopeExclude() != null && !getClasspathDependencyScopeExclude().isEmpty() ) @@ -2459,38 +2451,16 @@ public abstract class AbstractSurefireMojo classpathArtifacts = filterArtifacts( classpathArtifacts, dependencyFilter ); } - for ( Artifact artifact : classpathArtifacts ) - { - if ( artifact.getArtifactHandler().isAddedToClasspath() ) - { - File file = artifact.getFile(); - if ( file != null ) - { - classpath.add( file.getPath() ); - } - } - } - - // Add additional configured elements to the classpath - if ( getAdditionalClasspathElements() != null ) - { - for ( String classpathElement : getAdditionalClasspathElements() ) - { - if ( classpathElement != null ) - { - addAll( classpath, split( classpathElement, "," ) ); - } - } - } + return new TestClassPath( classpathArtifacts, getClassesDirectory(), + getTestClassesDirectory(), getAdditionalClasspathElements(), logger ); // adding TestNG MethodSelector to the classpath // Todo: move - if ( getTestNgArtifact() != null ) + // todo: why t use it in general, and surefire-grouper + /*if ( getTestNgArtifact() != null ) { addTestNgUtilsArtifacts( classpath ); - } - - return new Classpath( classpath ); + }*/ } private void addTestNgUtilsArtifacts( List classpath ) @@ -2836,12 +2806,12 @@ public abstract class AbstractSurefireMojo @Override @Nonnull - public Classpath getProviderClasspath() + public Set getProviderClasspath() throws ArtifactResolutionException, ArtifactNotFoundException { Artifact surefireArtifact = getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter" ); - return dependencyResolver.getProviderClasspath( "surefire-testng", surefireArtifact.getBaseVersion(), - testNgArtifact ); + String version = surefireArtifact.getBaseVersion(); + return dependencyResolver.getProviderClasspath( "surefire-testng", version, testNgArtifact ); } } @@ -2867,14 +2837,13 @@ public abstract class AbstractSurefireMojo @Override @Nonnull - public Classpath getProviderClasspath() + public Set getProviderClasspath() throws ArtifactResolutionException, ArtifactNotFoundException { // add the JUnit provider as default - it doesn't require JUnit to be present, // since it supports POJO tests. - return dependencyResolver.getProviderClasspath( "surefire-junit3", surefireBooterArtifact.getBaseVersion(), - null ); - + String version = surefireBooterArtifact.getBaseVersion(); + return dependencyResolver.getProviderClasspath( "surefire-junit3", version, null ); } } @@ -2910,13 +2879,12 @@ public abstract class AbstractSurefireMojo @Override @Nonnull - public Classpath getProviderClasspath() + public Set getProviderClasspath() throws ArtifactResolutionException, ArtifactNotFoundException { - return dependencyResolver.getProviderClasspath( "surefire-junit4", surefireBooterArtifact.getBaseVersion(), - null ); + String version = surefireBooterArtifact.getBaseVersion(); + return dependencyResolver.getProviderClasspath( "surefire-junit4", version, null ); } - } final class JUnitPlatformProviderInfo @@ -2929,27 +2897,32 @@ public abstract class AbstractSurefireMojo this.junitArtifact = junitArtifact; } - @Nonnull public String getProviderName() + @Override + @Nonnull + public String getProviderName() { return "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider"; } + @Override public boolean isApplicable() { return junitArtifact != null; } + @Override public void addProviderProperties() throws MojoExecutionException { convertGroupParameters(); } - public Classpath getProviderClasspath() + @Override + @Nonnull + public Set getProviderClasspath() throws ArtifactResolutionException, ArtifactNotFoundException { - return dependencyResolver.getProviderClasspath( "surefire-junit-platform", - surefireBooterArtifact.getBaseVersion(), - null ); + String version = surefireBooterArtifact.getBaseVersion(); + return dependencyResolver.getProviderClasspath( "surefire-junit-platform", version, null ); } } @@ -2994,11 +2967,11 @@ public abstract class AbstractSurefireMojo @Override @Nonnull - public Classpath getProviderClasspath() + public Set getProviderClasspath() throws ArtifactResolutionException, ArtifactNotFoundException { - return dependencyResolver.getProviderClasspath( "surefire-junit47", surefireBooterArtifact.getBaseVersion(), - null ); + String version = surefireBooterArtifact.getBaseVersion(); + return dependencyResolver.getProviderClasspath( "surefire-junit47", version, null ); } } @@ -3044,7 +3017,7 @@ public abstract class AbstractSurefireMojo @Override @Nonnull - public Classpath getProviderClasspath() + public Set getProviderClasspath() throws ArtifactResolutionException, ArtifactNotFoundException { return dependencyResolver.addProviderToClasspath( pluginArtifactMap, getMojoArtifact() ); diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ClasspathCache.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ClasspathCache.java index b8b2e2d..3bb1ac2 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ClasspathCache.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ClasspathCache.java @@ -19,7 +19,12 @@ package org.apache.maven.plugin.surefire; * under the License. */ +import java.util.ArrayList; +import java.util.Collection; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; + +import org.apache.maven.artifact.Artifact; import org.apache.maven.surefire.booter.Classpath; import javax.annotation.Nonnull; @@ -41,4 +46,16 @@ public class ClasspathCache { CLASSPATHS.put( key, classpath ); } + + public static Classpath setCachedClasspath( @Nonnull String key, @Nonnull Set artifacts ) + { + Collection files = new ArrayList(); + for ( Artifact artifact : artifacts ) + { + files.add( artifact.getFile().getAbsolutePath() ); + } + Classpath classpath = new Classpath( files ); + setCachedClasspath( key, classpath ); + return classpath; + } } diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java index a3fb88e..e99cc82 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java @@ -19,12 +19,12 @@ package org.apache.maven.plugin.surefire; * under the License. */ -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.surefire.booter.Classpath; import javax.annotation.Nonnull; +import java.util.Set; /** * @author Kristian Rosenvold @@ -37,8 +37,8 @@ public interface ProviderInfo boolean isApplicable(); @Nonnull - Classpath getProviderClasspath() - throws ArtifactResolutionException, ArtifactNotFoundException; + Set getProviderClasspath() + throws AbstractArtifactResolutionException; void addProviderProperties() throws MojoExecutionException; } diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java index a43c4de..f33a316 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java @@ -19,10 +19,6 @@ package org.apache.maven.plugin.surefire; * under the License. */ -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; @@ -37,11 +33,19 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.surefire.booter.Classpath; import org.apache.maven.plugin.surefire.log.api.ConsoleLogger; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static java.util.Collections.singleton; +import static org.apache.maven.artifact.Artifact.SCOPE_TEST; +import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; /** * Does dependency resolution and artifact handling for the surefire plugin. @@ -123,65 +127,55 @@ public class SurefireDependencyResolver Artifact originatingArtifact = artifactFactory.createBuildArtifact( "dummy", "dummy", "1.0", "jar" ); - return artifactResolver.resolveTransitively( Collections.singleton( providerArtifact ), originatingArtifact, + return artifactResolver.resolveTransitively( singleton( providerArtifact ), originatingArtifact, localRepository, remoteRepositories, artifactMetadataSource, filter ); } @Nonnull - public Classpath getProviderClasspath( String provider, String version, Artifact filteredArtifact ) + @SuppressWarnings( "unchecked" ) + public Set getProviderClasspath( String provider, String version, Artifact filteredArtifact ) throws ArtifactNotFoundException, ArtifactResolutionException { - Classpath classPath = ClasspathCache.getCachedClassPath( provider ); - if ( classPath == null ) - { - Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", provider, - VersionRange.createFromVersion( - version ), "jar", null, - Artifact.SCOPE_TEST ); - ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); - List files = new ArrayList(); + Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", + provider, createFromVersion( version ), "jar", null, SCOPE_TEST ); + + ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); + if ( log.isDebugEnabled() ) + { for ( Object o : result.getArtifacts() ) { Artifact artifact = (Artifact) o; - - log.debug( - "Adding to " + pluginName + " test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " - + artifact.getScope() ); - - files.add( artifact.getFile().getAbsolutePath() ); + String artifactPath = artifact.getFile().getAbsolutePath(); + String scope = artifact.getScope(); + log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); } - classPath = new Classpath( files ); - ClasspathCache.setCachedClasspath( provider, classPath ); } - return classPath; + + return result.getArtifacts(); } - public Classpath addProviderToClasspath( Map pluginArtifactMap, Artifact surefireArtifact ) + public Set addProviderToClasspath( Map pluginArtifactMap, Artifact surefireArtifact ) throws ArtifactResolutionException, ArtifactNotFoundException { - List files = new ArrayList(); + Set providerArtifacts = new LinkedHashSet(); if ( surefireArtifact != null ) { - final ArtifactResolutionResult artifactResolutionResult = resolveArtifact( null, surefireArtifact ); + ArtifactResolutionResult artifactResolutionResult = resolveArtifact( null, surefireArtifact ); for ( Artifact artifact : pluginArtifactMap.values() ) { if ( !artifactResolutionResult.getArtifacts().contains( artifact ) ) { - files.add( artifact.getFile().getAbsolutePath() ); + providerArtifacts.add( artifact ); } } } else { // Bit of a brute force strategy if not found. Should probably be improved - for ( Artifact artifact : pluginArtifactMap.values() ) - { - files.add( artifact.getFile().getPath() ); - } + providerArtifacts.addAll( pluginArtifactMap.values() ); } - return new Classpath( files ); + return providerArtifacts; } - } diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java new file mode 100644 index 0000000..bad0b31 --- /dev/null +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/TestClassPath.java @@ -0,0 +1,115 @@ +package org.apache.maven.plugin.surefire; + +/* + * 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.artifact.Artifact; +import org.apache.maven.surefire.booter.Classpath; +import org.codehaus.plexus.logging.Logger; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import static java.util.Collections.addAll; +import static org.apache.maven.shared.utils.StringUtils.split; + +final class TestClassPath +{ + private final Iterable artifacts; + private final File classesDirectory; + private final File testClassesDirectory; + private final String[] additionalClasspathElements; + private final Logger logger; + + TestClassPath( Iterable artifacts, + File classesDirectory, + File testClassesDirectory, + String[] additionalClasspathElements, + Logger logger ) + { + this.artifacts = artifacts; + this.classesDirectory = classesDirectory; + this.testClassesDirectory = testClassesDirectory; + this.additionalClasspathElements = additionalClasspathElements; + this.logger = logger; + } + + void avoidArtifactDuplicates( Set providerArtifacts ) + { + for ( Artifact artifact : artifacts ) + { + Iterator it = providerArtifacts.iterator(); + while ( it.hasNext() ) + { + Artifact providerArtifact = it.next(); + String classifier1 = providerArtifact.getClassifier(); + String classifier2 = artifact.getClassifier(); + if ( providerArtifact.getGroupId().equals( artifact.getGroupId() ) + && providerArtifact.getArtifactId().equals( artifact.getArtifactId() ) + && providerArtifact.getType().equals( artifact.getType() ) + && ( classifier1 == null ? classifier2 == null : classifier1.equals( classifier2 ) ) ) + { + it.remove(); + if ( logger.isDebugEnabled() ) + { + logger.debug( "Removed artifact " + providerArtifact + " from provider. " + + "Already appears in test classpath." ); + } + } + } + } + } + + Classpath toClasspath() + { + List classpath = new ArrayList(); + classpath.add( testClassesDirectory.getAbsolutePath() ); + classpath.add( classesDirectory.getAbsolutePath() ); + for ( Artifact artifact : artifacts ) + { + if ( artifact.getArtifactHandler().isAddedToClasspath() ) + { + File file = artifact.getFile(); + if ( file != null ) + { + classpath.add( file.getAbsolutePath() ); + } + } + } + if ( additionalClasspathElements != null ) + { + for ( String additionalClasspathElement : additionalClasspathElements ) + { + if ( additionalClasspathElement != null ) + { + addAll( classpath, split( additionalClasspathElement, "," ) ); + } + } + } + // todo: why t use it in general, and surefire-grouper + /*if ( getTestNgArtifact() != null ) + { + addTestNgUtilsArtifacts( classpath ); + }*/ + return new Classpath( classpath ); + } +} diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java index 8310fe3..96a2a5c 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java @@ -20,6 +20,9 @@ package org.apache.maven.plugin.surefire; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.surefire.log.PluginConsoleLogger; @@ -32,6 +35,7 @@ import org.apache.maven.surefire.util.DefaultScanResult; import org.codehaus.plexus.languages.java.jpms.LocationManager; import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest; import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult; +import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult.ModuleNameSource; import org.codehaus.plexus.logging.Logger; import org.junit.BeforeClass; import org.junit.Test; @@ -47,12 +51,13 @@ import java.nio.file.Path; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; -import static java.io.File.separatorChar; import static java.util.Arrays.asList; import static java.util.Collections.singleton; import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT; +import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; import static org.apache.maven.surefire.booter.SystemUtils.isBuiltInJava7AtLeast; import static org.fest.assertions.Assertions.assertThat; import static org.junit.Assume.assumeTrue; @@ -78,6 +83,9 @@ import static org.powermock.reflect.Whitebox.invokeMethod; public class AbstractSurefireMojoJava7PlusTest { @Mock + private ArtifactHandler handler; + + @Mock private LocationManager locationManager; @BeforeClass @@ -94,36 +102,62 @@ public class AbstractSurefireMojoJava7PlusTest doReturn( locationManager ) .when( mojo, "getLocationManager" ); - Classpath testClasspath = new Classpath( asList( "non-modular.jar", "modular.jar", - "target" + separatorChar + "classes", "junit.jar", "hamcrest.jar" ) ); + when( handler.isAddedToClasspath() ).thenReturn( true ); + + VersionRange v1 = createFromVersion( "1" ); + Artifact modular = new DefaultArtifact( "x", "modular", v1, "compile", "jar", "", handler ); + modular.setFile( mockFile( "modular.jar" ) ); + + VersionRange v2 = createFromVersion( "1" ); + Artifact nonModular = new DefaultArtifact( "x", "non-modular", v2, "test", "jar", "", handler ); + nonModular.setFile( mockFile( "non-modular.jar" ) ); + + VersionRange v3 = createFromVersion( "4.12" ); + Artifact junit = new DefaultArtifact( "junit", "junit", v3, "test", "jar", "", handler ); + junit.setFile( mockFile( "junit.jar" ) ); + + VersionRange v4 = createFromVersion( "1.3.0" ); + Artifact hamcrest = new DefaultArtifact( "org.hamcrest", "hamcrest-core", v4, "test", "jar", "", handler ); + hamcrest.setFile( mockFile( "hamcrest.jar" ) ); + + File classesDir = mockFile( "classes" ); + File testClassesDir = mockFile( "test-classes" ); + + TestClassPath testClasspath = + new TestClassPath( asList( modular, nonModular, junit, hamcrest ), classesDir, testClassesDir, + null, null ); doReturn( testClasspath ).when( mojo, "generateTestClasspath" ); doReturn( 1 ).when( mojo, "getEffectiveForkCount" ); doReturn( true ).when( mojo, "effectiveIsEnableAssertions" ); when( mojo.isChildDelegation() ).thenReturn( false ); - when( mojo.getTestClassesDirectory() ).thenReturn( new File( "target" + separatorChar + "test-classes" ) ); + when( mojo.getTestClassesDirectory() ).thenReturn( testClassesDir ); DefaultScanResult scanResult = mock( DefaultScanResult.class ); when( scanResult.getClasses() ).thenReturn( asList( "org.apache.A", "org.apache.B" ) ); ClassLoaderConfiguration classLoaderConfiguration = new ClassLoaderConfiguration( false, true ); - Classpath providerClasspath = new Classpath( singleton( "surefire-provider.jar" ) ); + VersionRange v5 = createFromVersion( "1" ); + Artifact provider = new DefaultArtifact( "org.apache.maven.surefire", "surefire-provider", v5, "runtime", + "jar", "", handler ); + provider.setFile( mockFile( "surefire-provider.jar" ) ); + Set providerClasspath = singleton( provider ); - File moduleInfo = new File( "target" + separatorChar + "classes" + separatorChar + "module-info.class" ); + File moduleInfo = mockFile( "classes/module-info.class" ); @SuppressWarnings( "unchecked" ) ResolvePathsRequest req = mock( ResolvePathsRequest.class ); mockStatic( ResolvePathsRequest.class ); - when( ResolvePathsRequest.withStrings( eq( testClasspath.getClassPath() ) ) ).thenReturn( req ); + when( ResolvePathsRequest.ofStrings( eq( testClasspath.toClasspath().getClassPath() ) ) ).thenReturn( req ); when( req.setMainModuleDescriptor( eq( moduleInfo.getAbsolutePath() ) ) ).thenReturn( req ); @SuppressWarnings( "unchecked" ) ResolvePathsResult res = mock( ResolvePathsResult.class ); when( res.getClasspathElements() ).thenReturn( asList( "non-modular.jar", "junit.jar", "hamcrest.jar" ) ); - Map mod = new LinkedHashMap(); + Map mod = new LinkedHashMap(); mod.put( "modular.jar", null ); - mod.put( "target" + separatorChar + "classes", null ); + mod.put( "classes", null ); when( res.getModulepathElements() ).thenReturn( mod ); when( locationManager.resolvePaths( eq( req ) ) ).thenReturn( res ); @@ -132,7 +166,7 @@ public class AbstractSurefireMojoJava7PlusTest doNothing().when( logger ).debug( anyString() ); when( mojo.getConsoleLogger() ).thenReturn( new PluginConsoleLogger( logger ) ); - StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigForModularClasspath", + StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigWithModularPath", classLoaderConfiguration, providerClasspath, "org.asf.Provider", moduleInfo, scanResult ); verify( mojo, times( 1 ) ).effectiveIsEnableAssertions(); @@ -142,7 +176,7 @@ public class AbstractSurefireMojoJava7PlusTest verify( mojo, times( 1 ) ).getTestClassesDirectory(); verify( scanResult, times( 1 ) ).getClasses(); verifyStatic( ResolvePathsRequest.class, times( 1 ) ); - ResolvePathsRequest.withStrings( eq( testClasspath.getClassPath() ) ); + ResolvePathsRequest.ofStrings( eq( testClasspath.toClasspath().getClassPath() ) ); verify( req, times( 1 ) ).setMainModuleDescriptor( eq( moduleInfo.getAbsolutePath() ) ); verify( res, times( 1 ) ).getClasspathElements(); verify( res, times( 1 ) ).getModulepathElements(); @@ -151,7 +185,7 @@ public class AbstractSurefireMojoJava7PlusTest verify( logger, times( 6 ) ).debug( argument.capture() ); assertThat( argument.getAllValues() ) .containsExactly( "test classpath: non-modular.jar junit.jar hamcrest.jar", - "test modulepath: modular.jar target" + separatorChar + "classes", + "test modulepath: modular.jar classes", "provider classpath: surefire-provider.jar", "test(compact) classpath: non-modular.jar junit.jar hamcrest.jar", "test(compact) modulepath: modular.jar classes", @@ -168,15 +202,16 @@ public class AbstractSurefireMojoJava7PlusTest assertThat( conf.getClasspathConfiguration() ).isNotNull(); assertThat( ( Object ) conf.getClasspathConfiguration().getTestClasspath() ) .isEqualTo( new Classpath( res.getClasspathElements() ) ); - assertThat( ( Object ) conf.getClasspathConfiguration().getProviderClasspath() ).isSameAs( providerClasspath ); + assertThat( ( Object ) conf.getClasspathConfiguration().getProviderClasspath() ) + .isEqualTo( new Classpath( singleton( "surefire-provider.jar" ) ) ); assertThat( conf.getClasspathConfiguration() ).isInstanceOf( ModularClasspathConfiguration.class ); ModularClasspathConfiguration mcc = ( ModularClasspathConfiguration ) conf.getClasspathConfiguration(); assertThat( mcc.getModularClasspath().getModuleDescriptor() ).isEqualTo( moduleInfo ); assertThat( mcc.getModularClasspath().getPackages() ).containsOnly( "org.apache" ); - assertThat( mcc.getModularClasspath().getPatchFile() ) - .isEqualTo( new File( "target" + separatorChar + "test-classes" ) ); + assertThat( mcc.getModularClasspath().getPatchFile().getAbsolutePath() ) + .isEqualTo( "test-classes" ); assertThat( mcc.getModularClasspath().getModulePath() ) - .containsExactly( "modular.jar", "target" + separatorChar + "classes" ); + .containsExactly( "modular.jar", "classes" ); assertThat( ( Object ) mcc.getTestClasspath() ).isEqualTo( new Classpath( res.getClasspathElements() ) ); } @@ -222,6 +257,13 @@ public class AbstractSurefireMojoJava7PlusTest .isTrue(); } + private static File mockFile( String absolutePath ) + { + File f = mock( File.class ); + when( f.getAbsolutePath() ).thenReturn( absolutePath ); + return f; + } + public static class Mojo extends AbstractSurefireMojo { 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 481d91e..04528ab 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 @@ -20,7 +20,9 @@ package org.apache.maven.plugin.surefire; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.surefire.log.PluginConsoleLogger; @@ -33,23 +35,28 @@ import org.codehaus.plexus.logging.Logger; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.mockito.Mock; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import static java.io.File.separatorChar; import static java.util.Arrays.asList; import static java.util.Collections.singleton; import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; +import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; @@ -67,6 +74,9 @@ import static org.powermock.reflect.Whitebox.invokeMethod; @PrepareForTest( AbstractSurefireMojo.class ) public class AbstractSurefireMojoTest { + @Mock + private ArtifactHandler handler; + private final Mojo mojo = new Mojo(); @Test @@ -121,21 +131,19 @@ public class AbstractSurefireMojoTest when( project.getArtifacts() ).thenReturn( artifacts ); when( mojo.getProject() ).thenReturn( project ); - Classpath cp = invokeMethod( mojo, "generateTestClasspath" ); + TestClassPath cp = invokeMethod( mojo, "generateTestClasspath" ); verifyPrivate( mojo, times( 1 ) ).invoke( "generateTestClasspath" ); verify( mojo, times( 1 ) ).getClassesDirectory(); verify( mojo, times( 1 ) ).getTestClassesDirectory(); verify( mojo, times( 3 ) ).getClasspathDependencyScopeExclude(); verify( mojo, times( 2 ) ).getClasspathDependencyExcludes(); - verify( artifactHandler, times( 1 ) ).isAddedToClasspath(); - verifyPrivate( mojo, times( 1 ) ).invoke( "getTestNgArtifact" ); - verifyPrivate( mojo, times( 1 ) ).invoke( "addTestNgUtilsArtifacts", eq( cp.getClassPath() ) ); - - assertThat( cp.getClassPath() ).hasSize( 3 ); - assertThat( cp.getClassPath().get( 0 ) ).endsWith( "test-classes" ); - assertThat( cp.getClassPath().get( 1 ) ).endsWith( "classes" ); - assertThat( cp.getClassPath().get( 2 ) ).endsWith( "a2-2.jar" ); + verify( mojo, times( 1 ) ).getAdditionalClasspathElements(); + + assertThat( cp.toClasspath().getClassPath() ).hasSize( 3 ); + assertThat( cp.toClasspath().getClassPath().get( 0 ) ).endsWith( "test-classes" ); + assertThat( cp.toClasspath().getClassPath().get( 1 ) ).endsWith( "classes" ); + assertThat( cp.toClasspath().getClassPath().get( 2 ) ).endsWith( "a2-2.jar" ); } @Test @@ -143,7 +151,37 @@ public class AbstractSurefireMojoTest throws Exception { AbstractSurefireMojo mojo = spy( this.mojo ); - Classpath testClasspath = new Classpath( asList( "junit.jar", "hamcrest.jar" ) ); + + Artifact common = new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-common", + createFromVersion( "1" ), "runtime", "jar", "", handler ); + common.setFile( mockFile( "maven-surefire-common.jar" ) ); + + + Artifact api = new DefaultArtifact( "org.apache.maven.surefire", "surefire-api", + createFromVersion( "1" ), "runtime", "jar", "", handler ); + api.setFile( mockFile( "surefire-api.jar" ) ); + + Map providerArtifactsMap = new HashMap(); + providerArtifactsMap.put( "org.apache.maven.surefire:maven-surefire-common", common ); + providerArtifactsMap.put( "org.apache.maven.surefire:surefire-api", api ); + + when( mojo.getPluginArtifactMap() ) + .thenReturn( providerArtifactsMap ); + + when( handler.isAddedToClasspath() ).thenReturn( true ); + + VersionRange v1 = createFromVersion( "4.12" ); + Artifact junit = new DefaultArtifact( "junit", "junit", v1, "test", "jar", "", handler ); + junit.setFile( mockFile( "junit.jar" ) ); + + VersionRange v2 = createFromVersion( "1.3.0" ); + Artifact hamcrest = new DefaultArtifact( "org.hamcrest", "hamcrest-core", v2, "test", "jar", "", handler ); + hamcrest.setFile( mockFile( "hamcrest.jar" ) ); + + File classesDir = mockFile( "classes" ); + File testClassesDir = mockFile( "test-classes" ); + TestClassPath testClasspath = + new TestClassPath( asList( junit, hamcrest ), classesDir, testClassesDir, null, null ); doReturn( testClasspath ).when( mojo, "generateTestClasspath" ); doReturn( 1 ).when( mojo, "getEffectiveForkCount" ); @@ -152,18 +190,18 @@ public class AbstractSurefireMojoTest ClassLoaderConfiguration classLoaderConfiguration = new ClassLoaderConfiguration( false, true ); - Classpath providerClasspath = new Classpath( singleton( "surefire-provider.jar" ) ); - - Classpath inprocClasspath = - new Classpath( asList( "surefire-api.jar", "surefire-common.jar", "surefire-provider.jar" ) ); + VersionRange v3 = createFromVersion( "1" ); + Artifact provider = new DefaultArtifact( "x", "surefire-provider", v3, "runtime", "jar", "", handler ); + provider.setFile( mockFile( "surefire-provider.jar" ) ); + Set providerArtifacts = singleton( provider ); Logger logger = mock( Logger.class ); when( logger.isDebugEnabled() ).thenReturn( true ); doNothing().when( logger ).debug( anyString() ); when( mojo.getConsoleLogger() ).thenReturn( new PluginConsoleLogger( logger ) ); - StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigForNonModularClasspath", - classLoaderConfiguration, providerClasspath, inprocClasspath, "org.asf.Provider" ); + StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigWithClasspath", + classLoaderConfiguration, providerArtifacts, "org.asf.Provider" ); verify( mojo, times( 1 ) ).effectiveIsEnableAssertions(); verify( mojo, times( 1 ) ).isChildDelegation(); @@ -173,9 +211,9 @@ public class AbstractSurefireMojoTest ArgumentCaptor argument = ArgumentCaptor.forClass( String.class ); verify( logger, times( 4 ) ).debug( argument.capture() ); assertThat( argument.getAllValues() ) - .containsExactly( "test classpath: junit.jar hamcrest.jar", + .containsExactly( "test classpath: test-classes classes junit.jar hamcrest.jar", "provider classpath: surefire-provider.jar", - "test(compact) classpath: junit.jar hamcrest.jar", + "test(compact) classpath: test-classes classes junit.jar hamcrest.jar", "provider(compact) classpath: surefire-provider.jar" ); @@ -183,10 +221,15 @@ public class AbstractSurefireMojoTest .isSameAs( classLoaderConfiguration ); assertThat( ( Object ) conf.getClasspathConfiguration().getTestClasspath() ) - .isSameAs( testClasspath ); + .isEqualTo( testClasspath.toClasspath() ); + Collection files = new ArrayList(); + for ( Artifact providerArtifact : providerArtifacts ) + { + files.add( providerArtifact.getFile().getAbsolutePath() ); + } assertThat( ( Object ) conf.getClasspathConfiguration().getProviderClasspath() ) - .isSameAs( providerClasspath ); + .isEqualTo( new Classpath( files ) ); assertThat( ( Object ) conf.getClasspathConfiguration().isClassPathConfig() ) .isEqualTo( true ); @@ -602,4 +645,11 @@ public class AbstractSurefireMojoTest return null; } } + + private static File mockFile( String absolutePath ) + { + File f = mock( File.class ); + when( f.getAbsolutePath() ).thenReturn( absolutePath ); + return f; + } } diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java new file mode 100644 index 0000000..42a2b63 --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java @@ -0,0 +1,160 @@ +package org.apache.maven.surefire.its; + +/* + * 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.it.VerificationException; +import org.apache.maven.surefire.its.fixture.OutputValidator; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; +import static org.apache.maven.surefire.its.fixture.IsRegex.regex; +import static org.fest.assertions.Assertions.assertThat; +import static org.fest.util.Collections.set; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.junit.Assert.assertThat; + +@RunWith( Parameterized.class ) +public class JUnitPlatformEnginesIT + extends SurefireJUnit4IntegrationTestCase +{ + @Parameter + public String platform; + + @Parameter( 1 ) + public String jupiter; + + @Parameter( 2 ) + public String opentest; + + @Parameter( 3 ) + public String apiguardian; + + @Parameters(name = "{0}") + public static Iterable regexVersions() + { + ArrayList args = new ArrayList(); + args.add( new Object[] { "1.0.0", "5.0.0", "1.0.0", "1.0.0" } ); + args.add( new Object[] { "1.1.1", "5.1.1", "1.0.0", "1.0.0" } ); + args.add( new Object[] { "1.2.0", "5.2.0", "1.1.0", "1.0.0" } ); + args.add( new Object[] { "1.3.1", "5.3.1", "1.1.1", "1.0.0" } ); + args.add( new Object[] { "1.4.0-SNAPSHOT", "5.4.0-SNAPSHOT", "1.1.1", "1.0.0" } ); + return args; + } + + @Before + public void setUp() + { + assumeJavaVersion( 1.8d ); + } + + @Test + public void testToRegex() + { + String regex = toRegex( ".[]()*" ); + assertThat( regex ) + .isEqualTo( "\\.\\[\\]\\(\\).*" ); + } + + @Test + public void platform() throws VerificationException + { + OutputValidator validator = unpack( "junit-platform", '-' + platform ) + .sysProp( "jupiter.version", jupiter ) + .addGoal( "-X" ) + .executeTest() + .verifyErrorFree( 1 ); + + String testClasspath = "[DEBUG] test(compact) classpath:" + + " test-classes" + + " classes" + + " junit-jupiter-engine-" + jupiter + ".jar" + + " apiguardian-api-" + apiguardian + ".jar" + + " junit-platform-engine-" + platform + ".jar" + + " junit-platform-commons-" + platform + ".jar" + + " opentest4j-" + opentest + ".jar" + + " junit-jupiter-api-" + jupiter + ".jar"; + + List lines = validator.loadLogLines( startsWith( "[DEBUG] test(compact) classpath" ) ); + + assertThat( lines ) + .hasSize( 1 ); + + String line = lines.get( 0 ); + + assertThat( set( line ), regex( toRegex( testClasspath ) ) ); + + String providerClasspath = "[DEBUG] provider(compact) classpath:" + + " surefire-junit-platform-*.jar" + + " junit-platform-launcher-1.3.1.jar" + + " surefire-api-*.jar" + + " surefire-logger-api-*.jar"; + + lines = validator.loadLogLines( startsWith( "[DEBUG] provider(compact) classpath" ) ); + + assertThat( lines ) + .hasSize( 1 ); + + line = lines.get( 0 ); + + assertThat( set( line ), regex( toRegex( providerClasspath ) ) ); + + String bootClasspath = "[DEBUG] boot(compact) classpath:" + + " surefire-booter-*.jar" + + " surefire-api-*.jar" + + " surefire-logger-api-*.jar" + + " test-classes" + + " classes" + + " junit-jupiter-engine-" + jupiter + ".jar" + + " apiguardian-api-" + apiguardian + ".jar" + + " junit-platform-engine-" + platform + ".jar" + + " junit-platform-commons-" + platform + ".jar" + + " opentest4j-" + opentest + ".jar" + + " junit-jupiter-api-" + jupiter + ".jar" + + " surefire-junit-platform-*.jar" + + " junit-platform-launcher-1.3.1.jar"; + + lines = validator.loadLogLines( startsWith( "[DEBUG] boot(compact) classpath" ) ); + + assertThat( lines ) + .hasSize( 1 ); + + line = lines.get( 0 ); + + assertThat( set( line ), regex( toRegex( bootClasspath ) ) ); + } + + private static String toRegex(String text) { + return text.replaceAll( "\\.", "\\\\." ) + .replaceAll( "\\[", "\\\\[" ) + .replaceAll( "]", "\\\\]" ) + .replaceAll( "\\(", "\\\\(" ) + .replaceAll( "\\)", "\\\\)" ) + .replaceAll( "\\*", ".*" ); + } +} diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java index e1b808f..6c8d29d 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformIT.java @@ -23,66 +23,54 @@ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.junit.Before; import org.junit.Test; -import static java.lang.System.getProperty; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assume.assumeThat; +import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; public class JUnitPlatformIT - extends SurefireJUnit4IntegrationTestCase + extends SurefireJUnit4IntegrationTestCase { @Before public void setUp() { - assumeThat( "java.specification.version: ", - getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.8" ) ) ); + assumeJavaVersion( 1.8d ); } @Test public void testJupiterEngine() { - unpack( "/junit-platform-engine-jupiter" ).executeTest().verifyErrorFree( 5 ); + unpack( "/junit-platform-engine-jupiter" ) + .executeTest() + .verifyErrorFree( 5 ); } @Test public void testVintageEngine() { - unpack( "/junit-platform-engine-vintage" ).executeTest().verifyErrorFree( 1 ); + unpack( "/junit-platform-engine-vintage" ) + .executeTest() + .verifyErrorFree( 1 ); } @Test public void testJQwikEngine() { - unpack( "/junit-platform-engine-jqwik" ).executeTest().verifyErrorFree( 1 ); + unpack( "/junit-platform-engine-jqwik" ) + .executeTest() + .verifyErrorFree( 1 ); } @Test public void testMultipleEngines() { - unpack( "/junit-platform-multiple-engines" ).executeTest().verifyErrorFree( 7 ); - } - - @Test - public void testJUnitPlatform_1_0_0() - { - unpack( "/junit-platform-1.0.0" ).executeTest().verifyErrorFree( 1 ); - } - - @Test - public void testJUnitPlatform_1_1_1() - { - unpack( "/junit-platform-1.1.1" ).executeTest().verifyErrorFree( 1 ); - } - - @Test - public void testJUnitPlatform_1_2_0() - { - unpack( "/junit-platform-1.2.0" ).executeTest().verifyErrorFree( 1 ); + unpack( "/junit-platform-multiple-engines" ) + .executeTest() + .verifyErrorFree( 7 ); } @Test public void testTags() { - unpack( "/junit-platform-tags" ).executeTest().verifyErrorFree( 2 ); + unpack( "/junit-platform-tags" ) + .executeTest() + .verifyErrorFree( 2 ); } } diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/IsRegex.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/IsRegex.java new file mode 100644 index 0000000..09e8d0d --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/IsRegex.java @@ -0,0 +1,100 @@ +package org.apache.maven.surefire.its.fixture; + +/* + * 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.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; + +import java.util.Collections; +import java.util.Iterator; +import java.util.Set; + +import static java.util.Collections.singleton; + +/** + * Java Hamcrest Matcher with Regex. + */ +public final class IsRegex + extends BaseMatcher> +{ + public static Matcher> regex( Set expectedRegex ) + { + return new IsRegex( expectedRegex ); + } + + public static Matcher> regex( String expectedRegex ) + { + return new IsRegex( expectedRegex ); + } + + private final Set expectedRegex; + + private IsRegex( String expectedRegex ) + { + this.expectedRegex = singleton( expectedRegex ); + } + + private IsRegex( Set expectedRegex ) + { + this.expectedRegex = expectedRegex; + } + + @Override + public boolean matches( Object o ) + { + if ( o != null + && expectedRegex.size() == 1 ? isStringOrSet( o ) : isSet( o ) ) + { + //noinspection unchecked + Set actual = isSet( o ) ? ( Set ) o : singleton( ( String ) o ); + boolean matches = actual.size() == expectedRegex.size(); + Iterator regex = expectedRegex.iterator(); + for ( String s : actual ) + { + if ( s == null || !regex.hasNext() || !s.matches( regex.next() ) ) + { + matches = false; + } + } + return matches; + } + else + { + return false; + } + } + + @Override + public void describeTo( Description description ) + { + description.appendValue( expectedRegex ); + } + + private static boolean isStringOrSet( Object o ) + { + return o instanceof String || o instanceof Set; + } + + private static boolean isSet( Object o ) + { + return o instanceof Set; + } +} diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java index 882ed9c..56046f1 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java @@ -22,7 +22,7 @@ package org.apache.maven.surefire.its.fixture; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; -import java.util.Collection; +import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; @@ -39,9 +39,9 @@ import static org.hamcrest.MatcherAssert.assertThat; */ public class OutputValidator { - protected final Verifier verifier; + final Verifier verifier; - protected final File baseDir; + private final File baseDir; public OutputValidator( Verifier verifier ) { @@ -93,14 +93,7 @@ public class OutputValidator public OutputValidator assertThatLogLine( Matcher line, Matcher nTimes ) throws VerificationException { - int counter = 0; - for ( String log : loadLogLines() ) - { - if ( line.matches( log ) ) - { - counter++; - } - } + int counter = loadLogLines( line ).size(); assertThat( "log pattern does not match nTimes", counter, nTimes ); return this; } @@ -111,6 +104,20 @@ public class OutputValidator return verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false ); } + public List loadLogLines( Matcher line ) + throws VerificationException + { + List matchedLines = new ArrayList(); + for ( String log : loadLogLines() ) + { + if ( line.matches( log ) ) + { + matchedLines.add( log ); + } + } + return matchedLines; + } + public List loadFile( File file, Charset charset ) { //noinspection unchecked diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java index 2669b2f..2209061 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java @@ -24,17 +24,15 @@ import org.apache.maven.surefire.its.fixture.OutputValidator; import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.apache.maven.surefire.its.fixture.TestFile; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; import org.junit.Test; import java.nio.charset.Charset; import java.util.Collection; -import java.util.Iterator; import java.util.Set; import java.util.TreeSet; +import static org.apache.maven.surefire.its.fixture.IsRegex.regex; +import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.StringContains.containsString; @@ -48,14 +46,7 @@ import static org.junit.Assert.assertThat; public class Surefire1082ParallelJUnitParameterizedIT extends SurefireJUnit4IntegrationTestCase { - private static Set printOnlyTestLinesFromConsole( OutputValidator validator ) - throws VerificationException - { - return printOnlyTestLines( validator.loadLogLines() ); - } - private static Set printOnlyTestLinesFromOutFile( OutputValidator validator ) - throws VerificationException { TestFile report = validator.getSurefireReportsFile( "jiras.surefire1082.Jira1082Test-output.txt" ); report.assertFileExists(); @@ -63,7 +54,6 @@ public class Surefire1082ParallelJUnitParameterizedIT } private static Set printOnlyTestLines( Collection logs ) - throws VerificationException { Set log = new TreeSet(); for ( String line : logs ) @@ -76,11 +66,6 @@ public class Surefire1082ParallelJUnitParameterizedIT return log; } - private static Matcher> regex( Set r ) - { - return new IsRegex( r ); - } - private static void assertParallelRun( Set log ) { assertThat( log.size(), is( 4 ) ); @@ -115,7 +100,7 @@ public class Surefire1082ParallelJUnitParameterizedIT validator.assertThatLogLine( containsString( "Running jiras.surefire1082.Jira1082Test" ), is( 1 ) ); - Set log = printOnlyTestLinesFromConsole( validator ); + Set log = new TreeSet( validator.loadLogLines( startsWith( "class jiras.surefire1082." ) ) ); assertParallelRun( log ); } @@ -169,44 +154,4 @@ public class Surefire1082ParallelJUnitParameterizedIT { return unpack( "surefire-1082-parallel-junit-parameterized" ); } - - private static class IsRegex - extends BaseMatcher> - { - private final Set expectedRegex; - - IsRegex( Set expectedRegex ) - { - this.expectedRegex = expectedRegex; - } - - @Override - public boolean matches( Object o ) - { - if ( o != null && o instanceof Set ) - { - Set actual = (Set) o; - boolean matches = actual.size() == expectedRegex.size(); - Iterator regex = expectedRegex.iterator(); - for ( String s : actual ) - { - if ( s == null || !regex.hasNext() || !s.matches( regex.next() ) ) - { - matches = false; - } - } - return matches; - } - else - { - return false; - } - } - - @Override - public void describeTo( Description description ) - { - description.appendValue( expectedRegex ); - } - } } diff --git a/surefire-its/src/test/resources/junit-platform-1.1.1/pom.xml b/surefire-its/src/test/resources/junit-platform-1.1.1/pom.xml deleted file mode 100644 index 2555d8b..0000000 --- a/surefire-its/src/test/resources/junit-platform-1.1.1/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - 4.0.0 - - org.apache.maven.plugins.surefire - junit-platform-1.1.1 - 1.0 - Test for JUnit 5: Platform 1.1.1 + Jupiter 5.1.1 - - - 1.8 - 1.8 - - - - - - org.junit.jupiter - junit-jupiter-engine - 5.1.1 - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - - - diff --git a/surefire-its/src/test/resources/junit-platform-1.1.1/src/test/java/junitplatform_1_1_1/JUnitPlatform_1_1_1_Test.java b/surefire-its/src/test/resources/junit-platform-1.1.1/src/test/java/junitplatform_1_1_1/JUnitPlatform_1_1_1_Test.java deleted file mode 100644 index e1bc05e..0000000 --- a/surefire-its/src/test/resources/junit-platform-1.1.1/src/test/java/junitplatform_1_1_1/JUnitPlatform_1_1_1_Test.java +++ /dev/null @@ -1,37 +0,0 @@ -package junitplatform_1_1_1; - -/* - * 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 static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; - -class JUnitPlatform_1_1_1_Test -{ - - @Test - void test(TestInfo info) - { - assertEquals( "test(TestInfo)", info.getDisplayName(), "display name mismatch" ); - } - - -} diff --git a/surefire-its/src/test/resources/junit-platform-1.2.0/pom.xml b/surefire-its/src/test/resources/junit-platform-1.2.0/pom.xml deleted file mode 100644 index 8bc5638..0000000 --- a/surefire-its/src/test/resources/junit-platform-1.2.0/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - 4.0.0 - - org.apache.maven.plugins.surefire - junit-platform-1.2.0 - 1.0 - Test for JUnit 5: Platform 1.2.0 + Jupiter 5.2.0 - - - 1.8 - 1.8 - - - - - - org.junit.jupiter - junit-jupiter-engine - 5.2.0 - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - - - diff --git a/surefire-its/src/test/resources/junit-platform-1.2.0/src/test/java/junitplatform_1_2_0/JUnitPlatform_1_2_0_Test.java b/surefire-its/src/test/resources/junit-platform-1.2.0/src/test/java/junitplatform_1_2_0/JUnitPlatform_1_2_0_Test.java deleted file mode 100644 index c6ccbfc..0000000 --- a/surefire-its/src/test/resources/junit-platform-1.2.0/src/test/java/junitplatform_1_2_0/JUnitPlatform_1_2_0_Test.java +++ /dev/null @@ -1,37 +0,0 @@ -package junitplatform_1_2_0; - -/* - * 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 static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; - -class JUnitPlatform_1_2_0_Test -{ - - @Test - void test(TestInfo info) - { - assertEquals( "test(TestInfo)", info.getDisplayName(), "display name mismatch" ); - } - - -} diff --git a/surefire-its/src/test/resources/junit-platform-1.0.0/pom.xml b/surefire-its/src/test/resources/junit-platform/pom.xml similarity index 80% rename from surefire-its/src/test/resources/junit-platform-1.0.0/pom.xml rename to surefire-its/src/test/resources/junit-platform/pom.xml index 1b6fd59..02e5c00 100644 --- a/surefire-its/src/test/resources/junit-platform-1.0.0/pom.xml +++ b/surefire-its/src/test/resources/junit-platform/pom.xml @@ -26,7 +26,7 @@ org.apache.maven.plugins.surefire junit-platform-1.0.0 1.0 - Test for JUnit 5: Platform 1.0.0 + Jupiter 5.0.0 + Test for JUnit 5: Platform + Jupiter 1.8 @@ -43,7 +43,7 @@ org.junit.jupiter junit-jupiter-engine - 5.0.0 + ${jupiter.version} test @@ -57,4 +57,17 @@ + + + + oss-sonatype + oss-sonatype + https://oss.sonatype.org/content/repositories/snapshots/ + + true + always + ignore + + + diff --git a/surefire-its/src/test/resources/junit-platform-1.0.0/src/test/java/junitplatform_1_0_0/JUnitPlatform_1_0_0_Test.java b/surefire-its/src/test/resources/junit-platform/src/test/java/junitplatform/JUnitPlatformTest.java similarity index 97% rename from surefire-its/src/test/resources/junit-platform-1.0.0/src/test/java/junitplatform_1_0_0/JUnitPlatform_1_0_0_Test.java rename to surefire-its/src/test/resources/junit-platform/src/test/java/junitplatform/JUnitPlatformTest.java index 760d874..68bbe02 100644 --- a/surefire-its/src/test/resources/junit-platform-1.0.0/src/test/java/junitplatform_1_0_0/JUnitPlatform_1_0_0_Test.java +++ b/surefire-its/src/test/resources/junit-platform/src/test/java/junitplatform/JUnitPlatformTest.java @@ -24,14 +24,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -class JUnitPlatform_1_0_0_Test +class JUnitPlatformTest { - @Test void test(TestInfo info) { assertEquals( "test(TestInfo)", info.getDisplayName(), "display name mismatch" ); } - - } diff --git a/surefire-providers/surefire-junit-platform/pom.xml b/surefire-providers/surefire-junit-platform/pom.xml index 18be313..4a57646 100644 --- a/surefire-providers/surefire-junit-platform/pom.xml +++ b/surefire-providers/surefire-junit-platform/pom.xml @@ -86,12 +86,12 @@ org.junit.platform junit-platform-launcher - 1.2.0 + 1.3.1 org.junit.jupiter junit-jupiter-engine - 5.2.0 + 5.3.1 test diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java index 0cf526c..0ccb4fe 100644 --- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java +++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java @@ -48,6 +48,7 @@ import org.junit.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.engine.descriptor.ClassTestDescriptor; import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor; +import org.junit.platform.engine.ConfigurationParameters; import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.TestDescriptor.Type; import org.junit.platform.engine.TestExecutionResult; @@ -68,6 +69,8 @@ import org.mockito.InOrder; */ public class RunListenerAdapterTest { + private static final ConfigurationParameters CONFIG_PARAMS = mock(ConfigurationParameters.class); + private RunListener listener; private RunListenerAdapter adapter; @@ -444,7 +447,7 @@ public class RunListenerAdapterTest private static TestDescriptor newClassDescriptor() { - return new ClassTestDescriptor( UniqueId.root( "class", MyTestClass.class.getName() ), MyTestClass.class ); + return new ClassTestDescriptor( UniqueId.root( "class", MyTestClass.class.getName() ), MyTestClass.class, CONFIG_PARAMS ); } private static TestIdentifier newSourcelessChildIdentifierWithParent( diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java index efb0589..6d4394e 100644 --- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java +++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java @@ -31,6 +31,7 @@ import org.apache.maven.surefire.testset.TestListResolver; import org.junit.Test; import org.junit.jupiter.engine.descriptor.ClassTestDescriptor; import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor; +import org.junit.platform.engine.ConfigurationParameters; import org.junit.platform.engine.FilterResult; import org.junit.platform.engine.UniqueId; @@ -41,6 +42,8 @@ import org.junit.platform.engine.UniqueId; */ public class TestMethodFilterTest { + private static final ConfigurationParameters CONFIG_PARAMS = mock(ConfigurationParameters.class); + private final TestListResolver resolver = mock( TestListResolver.class ); private final TestMethodFilter filter = new TestMethodFilter( this.resolver ); @@ -90,7 +93,7 @@ public class TestMethodFilterTest private static ClassTestDescriptor newClassTestDescriptor() { UniqueId uniqueId = UniqueId.forEngine( "class" ); - return new ClassTestDescriptor( uniqueId, TestClass.class ); + return new ClassTestDescriptor( uniqueId, TestClass.class, CONFIG_PARAMS ); } public static class TestClass