diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml
index 05e5dc731a..805b24769f 100644
--- a/maven-surefire-common/pom.xml
+++ b/maven-surefire-common/pom.xml
@@ -166,6 +166,17 @@
+
+ org.codehaus.plexus
+ plexus-component-metadata
+
+
+
+ generate-metadata
+
+
+
+
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 d8b65ae968..1b88dee62d 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
@@ -20,17 +20,34 @@
* under the License.
*/
+import javax.annotation.Nonnull;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.ZipFile;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory;
-import org.apache.maven.plugin.surefire.extensions.SurefireConsoleOutputReporter;
-import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
-import org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
@@ -38,42 +55,34 @@
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.surefire.booterclient.ChecksumCalculator;
+import org.apache.maven.plugin.surefire.booterclient.ClasspathForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.ForkStarter;
-import org.apache.maven.plugin.surefire.booterclient.ClasspathForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.ModularClasspathForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.Platform;
-import org.apache.maven.plugin.surefire.booterclient.ProviderDetector;
+import org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory;
+import org.apache.maven.plugin.surefire.extensions.SurefireConsoleOutputReporter;
+import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
+import org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.util.DependencyScanner;
import org.apache.maven.plugin.surefire.util.DirectoryScanner;
+import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
-import org.apache.maven.surefire.shared.utils.io.FileUtils;
-import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
-import org.apache.maven.surefire.booter.Classpath;
-import org.apache.maven.surefire.booter.ClasspathConfiguration;
-import org.apache.maven.surefire.booter.KeyValueSource;
-import org.apache.maven.surefire.booter.ModularClasspath;
-import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
-import org.apache.maven.surefire.booter.ProcessCheckerType;
-import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.api.booter.ProviderParameterNames;
import org.apache.maven.surefire.api.booter.Shutdown;
-import org.apache.maven.surefire.booter.StartupConfiguration;
-import org.apache.maven.surefire.booter.SurefireBooterForkException;
-import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.surefire.api.cli.CommandLineOption;
-import org.apache.maven.surefire.extensions.ForkNodeFactory;
-import org.apache.maven.surefire.api.provider.SurefireProvider;
import org.apache.maven.surefire.api.report.ReporterConfiguration;
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
@@ -84,74 +93,67 @@
import org.apache.maven.surefire.api.testset.TestSetFailedException;
import org.apache.maven.surefire.api.util.DefaultScanResult;
import org.apache.maven.surefire.api.util.RunOrder;
+import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.KeyValueSource;
+import org.apache.maven.surefire.booter.ModularClasspath;
+import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
+import org.apache.maven.surefire.booter.ProcessCheckerType;
+import org.apache.maven.surefire.booter.ProviderConfiguration;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.apache.maven.surefire.booter.SurefireExecutionException;
+import org.apache.maven.surefire.extensions.ForkNodeFactory;
+import org.apache.maven.surefire.providerapi.ConfigurableProviderInfo;
+import org.apache.maven.surefire.providerapi.ProviderDetector;
+import org.apache.maven.surefire.providerapi.ProviderInfo;
+import org.apache.maven.surefire.providerapi.ProviderRequirements;
+import org.apache.maven.surefire.shared.utils.io.FileUtils;
import org.apache.maven.toolchain.DefaultToolchain;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.apache.maven.toolchain.java.DefaultJavaToolChain;
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
+import org.codehaus.plexus.languages.java.jpms.LocationManager;
import org.codehaus.plexus.languages.java.jpms.ResolvePathRequest;
import org.codehaus.plexus.languages.java.jpms.ResolvePathResult;
-import org.codehaus.plexus.logging.Logger;
-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 javax.annotation.Nonnull;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.zip.ZipFile;
+import org.codehaus.plexus.logging.Logger;
import static java.lang.Integer.parseInt;
-import static java.lang.Thread.currentThread;
import static java.util.Arrays.asList;
import static java.util.Collections.addAll;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
-import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
-import static org.apache.maven.surefire.shared.lang3.StringUtils.substringBeforeLast;
-import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
+import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.PluginFailureReason.COULD_NOT_RUN_DEFAULT_TESTS;
+import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.PluginFailureReason.COULD_NOT_RUN_SPECIFIED_TESTS;
+import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.PluginFailureReason.NONE;
import static org.apache.maven.plugin.surefire.SurefireDependencyResolver.isWithinVersionSpec;
-import static org.apache.maven.plugin.surefire.util.DependencyScanner.filter;
import static org.apache.maven.plugin.surefire.SurefireHelper.replaceThreadNumberPlaceholders;
-import static org.apache.maven.surefire.shared.utils.StringUtils.capitalizeFirstLetter;
-import static org.apache.maven.surefire.shared.utils.StringUtils.isEmpty;
-import static org.apache.maven.surefire.shared.utils.StringUtils.isNotBlank;
-import static org.apache.maven.surefire.shared.utils.StringUtils.isNotEmpty;
-import static org.apache.maven.surefire.shared.utils.StringUtils.split;
+import static org.apache.maven.plugin.surefire.util.DependencyScanner.filter;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.EXCLUDE_JUNIT5_ENGINES_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.INCLUDE_JUNIT5_ENGINES_PROP;
+import static org.apache.maven.surefire.api.suite.RunResult.failure;
+import static org.apache.maven.surefire.api.suite.RunResult.noTestsRun;
+import static org.apache.maven.surefire.api.util.ReflectionUtils.invokeMethodWithArray;
+import static org.apache.maven.surefire.api.util.ReflectionUtils.tryGetMethod;
+import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
import static org.apache.maven.surefire.booter.SystemUtils.JAVA_SPECIFICATION_VERSION;
import static org.apache.maven.surefire.booter.SystemUtils.endsWithJavaPath;
import static org.apache.maven.surefire.booter.SystemUtils.isBuiltInJava9AtLeast;
import static org.apache.maven.surefire.booter.SystemUtils.isJava9AtLeast;
import static org.apache.maven.surefire.booter.SystemUtils.toJdkHomeFromJvmExec;
import static org.apache.maven.surefire.booter.SystemUtils.toJdkVersionFromReleaseFile;
-import static org.apache.maven.surefire.api.suite.RunResult.failure;
-import static org.apache.maven.surefire.api.suite.RunResult.noTestsRun;
-import static org.apache.maven.surefire.api.util.ReflectionUtils.invokeMethodWithArray;
-import static org.apache.maven.surefire.api.util.ReflectionUtils.tryGetMethod;
-import static org.apache.maven.surefire.api.booter.ProviderParameterNames.INCLUDE_JUNIT5_ENGINES_PROP;
-import static org.apache.maven.surefire.api.booter.ProviderParameterNames.EXCLUDE_JUNIT5_ENGINES_PROP;
-import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.PluginFailureReason.NONE;
-import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.PluginFailureReason.COULD_NOT_RUN_SPECIFIED_TESTS;
-import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.PluginFailureReason.COULD_NOT_RUN_DEFAULT_TESTS;
+import static org.apache.maven.surefire.shared.lang3.StringUtils.substringBeforeLast;
+import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
+import static org.apache.maven.surefire.shared.utils.StringUtils.capitalizeFirstLetter;
+import static org.apache.maven.surefire.shared.utils.StringUtils.isEmpty;
+import static org.apache.maven.surefire.shared.utils.StringUtils.isNotBlank;
+import static org.apache.maven.surefire.shared.utils.StringUtils.isNotEmpty;
+import static org.apache.maven.surefire.shared.utils.StringUtils.split;
/**
* Abstract base class for running tests using Surefire.
@@ -171,8 +173,6 @@ public abstract class AbstractSurefireMojo
private static final Map JAVA_9_MATCHER = singletonMap( "version", "[9,)" );
private static final Platform PLATFORM = new Platform();
- private final ProviderDetector providerDetector = new ProviderDetector();
-
private final ClasspathCache classpathCache = new ClasspathCache();
/**
@@ -823,6 +823,9 @@ public abstract class AbstractSurefireMojo
@Component
private RepositorySystem repositorySystem;
+ @Component
+ private ProviderDetector providerDetector;
+
private Toolchain toolchain;
private int effectiveForkCount = -1;
@@ -1192,13 +1195,12 @@ protected List createProviders( TestClassPath testClasspath )
throws MojoExecutionException
{
Artifact junitDepArtifact = getJunitDepArtifact();
- return new ProviderList( new DynamicProviderInfo( null ),
- new JUnitPlatformProviderInfo( getJUnit5Artifact(), testClasspath ),
- new TestNgProviderInfo( getTestNgArtifact() ),
- new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ),
- new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ),
- new JUnit3ProviderInfo() )
- .resolve();
+ return providerDetector.resolve( new DynamicProviderInfo( null ),
+ new JUnitPlatformProviderInfo( getJUnit5Artifact(), testClasspath ),
+ new TestNgProviderInfo( getTestNgArtifact() ),
+ new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ),
+ new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ),
+ new JUnit3ProviderInfo() );
}
private SurefireProperties setupProperties()
@@ -3512,75 +3514,6 @@ public Set getProviderClasspath() throws MojoExecutionException
}
}
- /**
- * @author Kristian Rosenvold
- */
- final class ProviderList
- {
- private final ProviderInfo[] wellKnownProviders;
-
- private final ConfigurableProviderInfo dynamicProvider;
-
- ProviderList( ConfigurableProviderInfo dynamicProviderInfo, ProviderInfo... wellKnownProviders )
- {
- this.wellKnownProviders = wellKnownProviders;
- this.dynamicProvider = dynamicProviderInfo;
- }
-
- @Nonnull List resolve()
- {
- List providersToRun = new ArrayList<>();
- Set manuallyConfiguredProviders = getManuallyConfiguredProviders();
- for ( String name : manuallyConfiguredProviders )
- {
- ProviderInfo wellKnown = findByName( name );
- ProviderInfo providerToAdd = wellKnown != null ? wellKnown : dynamicProvider.instantiate( name );
- logDebugOrCliShowErrors( "Using configured provider " + providerToAdd.getProviderName() );
- providersToRun.add( providerToAdd );
- }
- return manuallyConfiguredProviders.isEmpty() ? autoDetectOneWellKnownProvider() : providersToRun;
- }
-
- @Nonnull private List autoDetectOneWellKnownProvider()
- {
- List providersToRun = new ArrayList<>();
- for ( ProviderInfo wellKnownProvider : wellKnownProviders )
- {
- if ( wellKnownProvider.isApplicable() )
- {
- providersToRun.add( wellKnownProvider );
- return providersToRun;
- }
- }
- return providersToRun;
- }
-
- private Set getManuallyConfiguredProviders()
- {
- try
- {
- ClassLoader cl = currentThread().getContextClassLoader();
- return providerDetector.lookupServiceNames( SurefireProvider.class, cl );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
- }
-
- private ProviderInfo findByName( String providerClassName )
- {
- for ( ProviderInfo wellKnownProvider : wellKnownProviders )
- {
- if ( wellKnownProvider.getProviderName().equals( providerClassName ) )
- {
- return wellKnownProvider;
- }
- }
- return null;
- }
- }
-
File createSurefireBootDirectoryInBuild()
{
File tmp = new File( getProjectBuildDirectory(), getTempDir() );
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ProviderDetector.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ProviderDetector.java
deleted file mode 100644
index fce3d4642b..0000000000
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ProviderDetector.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.apache.maven.plugin.surefire.booterclient;
-
-/*
- * 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.providerapi.ServiceLoader;
-
-import javax.annotation.Nonnull;
-import java.io.IOException;
-import java.util.Set;
-
-/**
- * @author Stephen Conolly
- * @author Kristian Rosenvold
- */
-public final class ProviderDetector
-{
- private final ServiceLoader spi = new ServiceLoader();
-
- @Nonnull
- public Set lookupServiceNames( Class> clazz, ClassLoader classLoader )
- throws IOException
- {
- return spi.lookup( clazz, classLoader );
- }
-}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ConfigurableProviderInfo.java b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ConfigurableProviderInfo.java
similarity index 91%
rename from maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ConfigurableProviderInfo.java
rename to maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ConfigurableProviderInfo.java
index 65e2b857c0..00d4fb23cf 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ConfigurableProviderInfo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ConfigurableProviderInfo.java
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.surefire;
+package org.apache.maven.surefire.providerapi;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -22,7 +22,7 @@
/**
* @author Kristian Rosenvold
*/
-interface ConfigurableProviderInfo
+public interface ConfigurableProviderInfo
extends ProviderInfo
{
ProviderInfo instantiate( String providerName );
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderDetector.java b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderDetector.java
new file mode 100644
index 0000000000..caaaa9d930
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderDetector.java
@@ -0,0 +1,104 @@
+package org.apache.maven.surefire.providerapi;
+
+/*
+ * 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 javax.annotation.Nonnull;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.surefire.api.provider.SurefireProvider;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+
+import static java.lang.Thread.currentThread;
+
+/**
+ * @author Kristian Rosenvold
+ */
+@Component( role = ProviderDetector.class )
+public final class ProviderDetector
+{
+ @Requirement
+ private Logger logger;
+
+ @Requirement
+ private ServiceLoader serviceLoader;
+
+ @Nonnull
+ public List resolve( ConfigurableProviderInfo dynamicProvider, ProviderInfo... wellKnownProviders )
+ {
+ List providersToRun = new ArrayList<>();
+ Set manuallyConfiguredProviders = getManuallyConfiguredProviders();
+ for ( String name : manuallyConfiguredProviders )
+ {
+ ProviderInfo wellKnown = findByName( name, wellKnownProviders );
+ ProviderInfo providerToAdd = wellKnown != null ? wellKnown : dynamicProvider.instantiate( name );
+ logger.info( "Using configured provider " + providerToAdd.getProviderName() );
+ providersToRun.add( providerToAdd );
+ }
+ return manuallyConfiguredProviders.isEmpty() ? autoDetectOneWellKnownProvider( wellKnownProviders )
+ : providersToRun;
+ }
+
+ @Nonnull
+ private List autoDetectOneWellKnownProvider( ProviderInfo... wellKnownProviders )
+ {
+ List providersToRun = new ArrayList<>();
+ for ( ProviderInfo wellKnownProvider : wellKnownProviders )
+ {
+ if ( wellKnownProvider.isApplicable() )
+ {
+ logger.info( "Using auto detected provider " + wellKnownProvider.getProviderName() );
+ providersToRun.add( wellKnownProvider );
+ return providersToRun;
+ }
+ }
+ return providersToRun;
+ }
+
+ private Set getManuallyConfiguredProviders()
+ {
+ try
+ {
+ ClassLoader cl = currentThread().getContextClassLoader();
+ return serviceLoader.lookup( SurefireProvider.class, cl );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+
+ private ProviderInfo findByName( String providerClassName, ProviderInfo... wellKnownProviders )
+ {
+ for ( ProviderInfo wellKnownProvider : wellKnownProviders )
+ {
+ if ( wellKnownProvider.getProviderName().equals( providerClassName ) )
+ {
+ return wellKnownProvider;
+ }
+ }
+ return null;
+ }
+}
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/surefire/providerapi/ProviderInfo.java
similarity index 96%
rename from maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java
rename to maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderInfo.java
index 66dd493419..dfa1d63808 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/surefire/providerapi/ProviderInfo.java
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.surefire;
+package org.apache.maven.surefire.providerapi;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,12 +19,12 @@
* under the License.
*/
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.MojoExecutionException;
-
-import javax.annotation.Nonnull;
import java.util.List;
import java.util.Set;
+import javax.annotation.Nonnull;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
/**
* @author Kristian Rosenvold
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderRequirements.java b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderRequirements.java
similarity index 80%
rename from maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderRequirements.java
rename to maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderRequirements.java
index 793667a946..e1d722915f 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderRequirements.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ProviderRequirements.java
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.surefire;
+package org.apache.maven.surefire.providerapi;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -24,30 +24,30 @@
*
* @see ProviderInfo#getJpmsArguments(ProviderRequirements)
*/
-final class ProviderRequirements
+public final class ProviderRequirements
{
private final boolean modularPath;
private final boolean mainModuleDescriptor;
private final boolean testModuleDescriptor;
- ProviderRequirements( boolean modularPath, boolean mainModuleDescriptor, boolean testModuleDescriptor )
+ public ProviderRequirements( boolean modularPath, boolean mainModuleDescriptor, boolean testModuleDescriptor )
{
this.modularPath = modularPath;
this.mainModuleDescriptor = mainModuleDescriptor;
this.testModuleDescriptor = testModuleDescriptor;
}
- boolean isModularPath()
+ public boolean isModularPath()
{
return modularPath;
}
- boolean hasMainModuleDescriptor()
+ public boolean hasMainModuleDescriptor()
{
return mainModuleDescriptor;
}
- boolean hasTestModuleDescriptor()
+ public boolean hasTestModuleDescriptor()
{
return testModuleDescriptor;
}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
index 89875a9c8a..e904eef095 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/surefire/providerapi/ServiceLoader.java
@@ -20,6 +20,7 @@
*/
import javax.annotation.Nonnull;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -29,6 +30,8 @@
import java.util.HashSet;
import java.util.Set;
+import org.codehaus.plexus.component.annotations.Component;
+
import static java.lang.Character.isJavaIdentifierPart;
import static java.lang.Character.isJavaIdentifierStart;
import static java.util.Collections.emptySet;
@@ -42,7 +45,8 @@
*
* @since 2.20
*/
-public final class ServiceLoader
+@Component( role = ServiceLoader.class )
+public class ServiceLoader
{
@Nonnull
@@ -67,7 +71,7 @@ public Set load( Class clazz, ClassLoader classLoader )
@Nonnull
public Set lookup( Class> clazz, ClassLoader classLoader )
- throws IOException
+ throws IOException
{
final String resourceName = "META-INF/services/" + clazz.getName();
@@ -90,7 +94,7 @@ public Set lookup( Class> clazz, ClassLoader classLoader )
@Nonnull
@SuppressWarnings( "checkstyle:innerassignment" )
private static Set lookupSpiImplementations( final Enumeration urlEnumeration )
- throws IOException
+ throws IOException
{
final Set names = new HashSet<>();
nextUrl:
@@ -143,7 +147,7 @@ private static Set lookupSpiImplementations( final Enumeration urlE
@Nonnull
private static BufferedReader getReader( @Nonnull URL url )
- throws IOException
+ throws IOException
{
final InputStream inputStream = url.openStream();
final InputStreamReader inputStreamReader = new InputStreamReader( inputStream );
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 c1f8dc8871..c3e144c70d 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
@@ -31,6 +31,8 @@
import org.apache.maven.surefire.extensions.ForkNodeFactory;
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.util.DefaultScanResult;
+import org.apache.maven.surefire.providerapi.ProviderInfo;
+import org.apache.maven.surefire.providerapi.ProviderRequirements;
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
import org.codehaus.plexus.languages.java.jpms.LocationManager;
import org.codehaus.plexus.languages.java.jpms.ResolvePathResult;
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 d5b08b5c8f..007d24d31c 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
@@ -60,6 +60,7 @@
import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.extensions.ForkNodeFactory;
+import org.apache.maven.surefire.providerapi.ProviderInfo;
import org.apache.maven.toolchain.Toolchain;
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
import org.codehaus.plexus.languages.java.jpms.LocationManager;
@@ -116,7 +117,7 @@
*/
@RunWith( PowerMockRunner.class )
@PrepareForTest( AbstractSurefireMojo.class )
-@PowerMockIgnore( { "org.jacoco.agent.rt.*", "com.vladium.emma.rt.*" } )
+@PowerMockIgnore( {"org.jacoco.agent.rt.*", "com.vladium.emma.rt.*"} )
public class AbstractSurefireMojoTest
{
@Rule
@@ -259,7 +260,7 @@ public void corruptedModuleDescriptor() throws Exception
File descriptorFile = new File( classesDir, "module-info.class" );
assertThat( descriptorFile.createNewFile() ).isTrue();
- write( descriptorFile.toPath(), new byte[]{(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE} );
+ write( descriptorFile.toPath(), new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE} );
File jdkHome = new File( System.getProperty( "java.home" ) );
ResolvePathResultWrapper wrapper = invokeMethod( mojo, "findModuleDescriptor", jdkHome );
@@ -285,13 +286,13 @@ public void shouldShowArray() throws Exception
when( mojo.getConsoleLogger() ).thenReturn( new PluginConsoleLogger( logger ) );
- Object[] array = { "ABC", "XYZ" };
+ Object[] array = {"ABC", "XYZ"};
invokeMethod( mojo, "showArray", array, "prefix" );
ArgumentCaptor argument = ArgumentCaptor.forClass( String.class );
verify( logger, times( 2 ) ).debug( argument.capture() );
assertThat( argument.getAllValues() )
- .containsExactly( "Setting prefix [ABC]", "Setting prefix [XYZ]" );
+ .containsExactly( "Setting prefix [ABC]", "Setting prefix [XYZ]" );
}
@Test
@@ -313,7 +314,7 @@ public void shouldShowMap() throws Exception
ArgumentCaptor argument = ArgumentCaptor.forClass( String.class );
verify( logger, times( 2 ) ).debug( argument.capture() );
assertThat( argument.getAllValues() )
- .containsExactly( "Setting prefix [ABC]=[123]", "Setting prefix [XYZ]=[987]" );
+ .containsExactly( "Setting prefix [ABC]=[123]", "Setting prefix [XYZ]=[987]" );
}
@Test
@@ -324,12 +325,12 @@ public void shouldRetainInPluginArtifacts() throws Exception
Artifact api = new DefaultArtifact( "g", "a", createFromVersionSpec( "1" ), "compile", "jar", "", null );
Set providerArtifacts = singleton( provider );
- Artifact[] inPluginArtifacts = { common, api };
+ Artifact[] inPluginArtifacts = {common, api};
Set inPluginClasspath = invokeMethod( AbstractSurefireMojo.class,
- "retainInProcArtifactsUnique", providerArtifacts, inPluginArtifacts );
+ "retainInProcArtifactsUnique", providerArtifacts, inPluginArtifacts );
assertThat( inPluginClasspath )
- .containsOnly( common );
+ .containsOnly( common );
}
@Test
@@ -340,12 +341,12 @@ public void shouldRetainInProcArtifactsUnique() throws Exception
Artifact api = new DefaultArtifact( "g", "a", createFromVersionSpec( "1" ), "compile", "jar", "", null );
Set providerArtifacts = singleton( provider );
- Artifact[] inPluginArtifacts = { common, api };
+ Artifact[] inPluginArtifacts = {common, api};
Set inPluginClasspath = invokeMethod( AbstractSurefireMojo.class,
- "retainInProcArtifactsUnique", providerArtifacts, inPluginArtifacts );
+ "retainInProcArtifactsUnique", providerArtifacts, inPluginArtifacts );
assertThat( inPluginClasspath )
- .containsOnly( common, api );
+ .containsOnly( common, api );
}
@Test
@@ -367,15 +368,15 @@ public void shouldCreateInProcClasspath() throws Exception
Classpath providerClasspath = new Classpath( singleton( provider.getFile().getAbsolutePath() ) );
Classpath inPluginClasspath = invokeMethod( AbstractSurefireMojo.class,
- "createInProcClasspath", providerClasspath, newArtifacts );
+ "createInProcClasspath", providerClasspath, newArtifacts );
Classpath expectedClasspath =
- new Classpath( asList( provider.getFile().getAbsolutePath(),
- common.getFile().getAbsolutePath(),
- api.getFile().getAbsolutePath() ) );
+ new Classpath( asList( provider.getFile().getAbsolutePath(),
+ common.getFile().getAbsolutePath(),
+ api.getFile().getAbsolutePath() ) );
- assertThat( (Object ) inPluginClasspath )
- .isEqualTo( expectedClasspath );
+ assertThat( (Object) inPluginClasspath )
+ .isEqualTo( expectedClasspath );
}
@@ -387,7 +388,7 @@ public void shouldGenerateTestClasspath() throws Exception
when( mojo.getMainBuildPath() ).thenReturn( new File( "target" + separatorChar + "classes" ) );
when( mojo.getTestClassesDirectory() ).thenReturn( new File( "target" + separatorChar + "test-classes" ) );
when( mojo.getClasspathDependencyScopeExclude() ).thenReturn( "runtime" );
- when( mojo.getClasspathDependencyExcludes() ).thenReturn( new String[]{ "g3:a3" } );
+ when( mojo.getClasspathDependencyExcludes() ).thenReturn( new String[] {"g3:a3"} );
doReturn( mock( Artifact.class ) ).when( mojo, "getTestNgArtifact" );
Set artifacts = new HashSet<>();
@@ -448,24 +449,24 @@ public void shouldGenerateTestClasspath() throws Exception
@Test
@SuppressWarnings( "checkstyle:linelength" )
public void shouldHaveStartupConfigForNonModularClasspath()
- throws Exception
+ throws Exception
{
AbstractSurefireMojo mojo = spy( this.mojo );
Artifact common = new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-common",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
common.setFile( mockFile( "maven-surefire-common.jar" ) );
Artifact ext = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-api",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
ext.setFile( mockFile( "surefire-extensions-api.jar" ) );
Artifact api = new DefaultArtifact( "org.apache.maven.surefire", "surefire-api",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
api.setFile( mockFile( "surefire-api.jar" ) );
Artifact loggerApi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-logger-api",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
loggerApi.setFile( mockFile( "surefire-logger-api.jar" ) );
Artifact spi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-spi",
@@ -490,7 +491,7 @@ public void shouldHaveStartupConfigForNonModularClasspath()
providerArtifactsMap.put( "org.apache.maven.surefire:surefire-shared-utils", utils );
when( mojo.getPluginArtifactMap() )
- .thenReturn( providerArtifactsMap );
+ .thenReturn( providerArtifactsMap );
when( handler.isAddedToClasspath() ).thenReturn( true );
@@ -505,7 +506,7 @@ public void shouldHaveStartupConfigForNonModularClasspath()
File classesDir = mockFile( "classes" );
File testClassesDir = mockFile( "test-classes" );
TestClassPath testClasspath =
- new TestClassPath( asList( junit, hamcrest ), classesDir, testClassesDir, null );
+ new TestClassPath( asList( junit, hamcrest ), classesDir, testClassesDir, null );
doReturn( testClasspath ).when( mojo, "generateTestClasspath" );
doReturn( 1 ).when( mojo, "getEffectiveForkCount" );
@@ -529,46 +530,46 @@ public void shouldHaveStartupConfigForNonModularClasspath()
when( providerInfo.getProviderClasspath() ).thenReturn( providerArtifacts );
StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigWithClasspath",
- classLoaderConfiguration, providerInfo, testClasspath );
+ classLoaderConfiguration, providerInfo, testClasspath );
verify( mojo, times( 1 ) ).effectiveIsEnableAssertions();
verify( mojo, times( 1 ) ).isChildDelegation();
ArgumentCaptor argument = ArgumentCaptor.forClass( String.class );
verify( logger, times( 6 ) ).debug( argument.capture() );
assertThat( argument.getAllValues() )
- .containsExactly( "test classpath: test-classes classes junit.jar hamcrest.jar",
+ .containsExactly( "test classpath: test-classes classes junit.jar hamcrest.jar",
"provider classpath: surefire-provider.jar",
"test(compact) classpath: test-classes classes junit.jar hamcrest.jar",
"provider(compact) classpath: surefire-provider.jar",
"in-process classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar",
"in-process(compact) classpath: surefire-provider.jar maven-surefire-common.jar surefire-booter.jar surefire-extensions-api.jar surefire-api.jar surefire-extensions-spi.jar surefire-logger-api.jar surefire-shared-utils.jar"
- );
+ );
assertThat( conf.getClassLoaderConfiguration() )
- .isSameAs( classLoaderConfiguration );
+ .isSameAs( classLoaderConfiguration );
- assertThat( ( Object ) conf.getClasspathConfiguration().getTestClasspath() )
- .isEqualTo( testClasspath.toClasspath() );
+ assertThat( (Object) conf.getClasspathConfiguration().getTestClasspath() )
+ .isEqualTo( testClasspath.toClasspath() );
Collection files = new ArrayList<>();
for ( Artifact providerArtifact : providerArtifacts )
{
files.add( providerArtifact.getFile().getAbsolutePath() );
}
- assertThat( ( Object ) conf.getClasspathConfiguration().getProviderClasspath() )
- .isEqualTo( new Classpath( files ) );
+ assertThat( (Object) conf.getClasspathConfiguration().getProviderClasspath() )
+ .isEqualTo( new Classpath( files ) );
- assertThat( ( Object ) conf.getClasspathConfiguration().isClassPathConfig() )
- .isEqualTo( true );
+ assertThat( (Object) conf.getClasspathConfiguration().isClassPathConfig() )
+ .isEqualTo( true );
- assertThat( ( Object ) conf.getClasspathConfiguration().isModularPathConfig() )
- .isEqualTo( false );
+ assertThat( (Object) conf.getClasspathConfiguration().isModularPathConfig() )
+ .isEqualTo( false );
- assertThat( ( Object ) conf.getClasspathConfiguration().isEnableAssertions() )
- .isEqualTo( true );
+ assertThat( (Object) conf.getClasspathConfiguration().isEnableAssertions() )
+ .isEqualTo( true );
assertThat( conf.getProviderClassName() )
- .isEqualTo( "org.asf.Provider" );
+ .isEqualTo( "org.asf.Provider" );
}
@Test
@@ -577,19 +578,19 @@ public void providerClasspathCachingIsNotSharedAcrossMojoInstances() throws Exce
ProviderInfo providerInfo = mock( ProviderInfo.class );
when( providerInfo.getProviderName() ).thenReturn( "test-provider" );
Artifact provider = new DefaultArtifact( "com.example", "provider", createFromVersion( "1" ), "runtime",
- "jar", "", handler );
+ "jar", "", handler );
provider.setFile( mockFile( "original-test-provider.jar" ) );
Set providerClasspath = singleton( provider );
when( providerInfo.getProviderClasspath() ).thenReturn( providerClasspath );
StartupConfiguration startupConfiguration = startupConfigurationForProvider( providerInfo );
assertThat( startupConfiguration.getClasspathConfiguration().getProviderClasspath().getClassPath() )
- .containsExactly( "original-test-provider.jar" );
+ .containsExactly( "original-test-provider.jar" );
provider.setFile( mockFile( "modified-test-provider.jar" ) );
startupConfiguration = startupConfigurationForProvider( providerInfo );
assertThat( startupConfiguration.getClasspathConfiguration().getProviderClasspath().getClassPath() )
- .containsExactly( "modified-test-provider.jar" );
+ .containsExactly( "modified-test-provider.jar" );
}
private StartupConfiguration startupConfigurationForProvider( ProviderInfo providerInfo ) throws Exception
@@ -604,22 +605,22 @@ private StartupConfiguration startupConfigurationForProvider( ProviderInfo provi
File classesDir = mockFile( "classes" );
File testClassesDir = mockFile( "test-classes" );
TestClassPath testClassPath =
- new TestClassPath( new ArrayList(), classesDir, testClassesDir, new String[0] );
+ new TestClassPath( new ArrayList(), classesDir, testClassesDir, new String[0] );
Artifact common = new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-common",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
common.setFile( mockFile( "maven-surefire-common.jar" ) );
Artifact ext = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-api",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
ext.setFile( mockFile( "surefire-extensions-api.jar" ) );
Artifact api = new DefaultArtifact( "org.apache.maven.surefire", "surefire-api",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
api.setFile( mockFile( "surefire-api.jar" ) );
Artifact loggerApi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-logger-api",
- createFromVersion( "1" ), "runtime", "jar", "", handler );
+ createFromVersion( "1" ), "runtime", "jar", "", handler );
loggerApi.setFile( mockFile( "surefire-logger-api.jar" ) );
Artifact spi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-spi",
@@ -759,7 +760,7 @@ public void shouldExistTmpDirectory() throws IOException
assertThat( new File( systemTmpDir, bootDir.getName() ) ).isDirectory();
assertThat( bootDir.getName() )
- .startsWith( tmpDir );
+ .startsWith( tmpDir );
File buildTmp = mojo.createSurefireBootDirectoryInBuild();
assertThat( buildTmp ).isNotNull();
@@ -771,7 +772,7 @@ public void shouldExistTmpDirectory() throws IOException
assertThat( tmp ).isNotNull();
assertThat( tmp ).isDirectory();
assertThat( IS_OS_WINDOWS ? new File( systemTmpDir, bootDir.getName() ) : new File( targetDir, tmpDir ) )
- .isDirectory();
+ .isDirectory();
}
@Test
@@ -779,7 +780,7 @@ public void shouldSmartlyResolveJUnit5ProviderWithJUnit4() throws Exception
{
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
final VersionRange surefireVersion = createFromVersion( "1" );
@@ -801,14 +802,14 @@ public void shouldSmartlyResolveJUnit5ProviderWithJUnit4() throws Exception
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDependency = new DefaultArtifact( "org.junit.vintage", "junit-vintage-engine",
createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
@@ -838,47 +839,47 @@ else if ( dependency.getArtifactId().equals( "junit-vintage-engine" ) )
final ArtifactResolutionResult surefireProviderResolutionResult = mock( ArtifactResolutionResult.class );
final ArtifactResolutionResult pluginDependencyResolutionResult = mock( ArtifactResolutionResult.class );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact artifact = req.getArtifact();
+ if ( artifact == surefireProvider )
+ {
+ return surefireProviderResolutionResult;
+ }
+ else if ( artifact == pluginDependency )
+ {
+ return pluginDependencyResolutionResult;
+ }
+ else if ( "org.junit.platform".equals( artifact.getGroupId() )
+ && "junit-platform-launcher".equals( artifact.getArtifactId() )
+ && "1.4.0".equals( artifact.getVersion() ) )
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact artifact = req.getArtifact();
- if ( artifact == surefireProvider )
- {
- return surefireProviderResolutionResult;
- }
- else if ( artifact == pluginDependency )
- {
- return pluginDependencyResolutionResult;
- }
- else if ( "org.junit.platform".equals( artifact.getGroupId() )
- && "junit-platform-launcher".equals( artifact.getArtifactId() )
- && "1.4.0".equals( artifact.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else
- {
- fail( artifact.getGroupId() + ":" + artifact.getArtifactId() );
- return null;
- }
+ return createExpectedJUnitPlatformLauncherResolutionResult();
}
- } );
+ else
+ {
+ fail( artifact.getGroupId() + ":" + artifact.getArtifactId() );
+ return null;
+ }
+ }
+ } );
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Set providerArtifacts = new HashSet<>();
providerArtifacts.add( surefireProvider );
providerArtifacts.add( java5 );
@@ -889,7 +890,7 @@ else if ( "org.junit.platform".equals( artifact.getGroupId() )
providerArtifacts.add( opentest4j );
when( surefireProviderResolutionResult.getArtifacts() )
- .thenReturn( providerArtifacts );
+ .thenReturn( providerArtifacts );
final Artifact pluginDep1 = new DefaultArtifact( "org.junit.vintage", "junit-vintage-engine",
createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
@@ -930,15 +931,15 @@ else if ( "org.junit.platform".equals( artifact.getGroupId() )
invokeMethod( mojo, "setupStuff" );
when( mojo.getSession().getProjectBuildingRequest() )
- .thenReturn( mock( ProjectBuildingRequest.class ) );
+ .thenReturn( mock( ProjectBuildingRequest.class ) );
PluginDescriptor pluginDescriptor = mock( PluginDescriptor.class );
mojo.setPluginDescriptor( pluginDescriptor );
Plugin p = mock( Plugin.class );
when( pluginDescriptor.getPlugin() )
- .thenReturn( p );
+ .thenReturn( p );
when( p.getDependencies() )
- .thenReturn( singletonList( toDependency( pluginDependency ) ) );
+ .thenReturn( singletonList( toDependency( pluginDependency ) ) );
Artifact junitPlatformArtifact = invokeMethod( mojo, "getJUnit5Artifact" );
assertThat( junitPlatformArtifact.getGroupId() ).isEqualTo( "org.junit.platform" );
@@ -946,36 +947,36 @@ else if ( "org.junit.platform".equals( artifact.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
Artifact expectedProvider = new DefaultArtifact( "org.apache.maven.surefire", "surefire-junit-platform",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedCommonJava5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedLauncher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
- createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedJUnit5Engine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedOpentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedPlatformCommons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedEngine = new DefaultArtifact( "org.junit.vintage", "junit-vintage-engine",
createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( prov.getProviderClasspath() )
- .hasSize( 8 )
- .containsOnly( expectedProvider, expectedCommonJava5, expectedLauncher, expectedApiguardian,
- expectedJUnit5Engine, expectedOpentest4j, expectedPlatformCommons, expectedEngine );
+ .hasSize( 8 )
+ .containsOnly( expectedProvider, expectedCommonJava5, expectedLauncher, expectedApiguardian,
+ expectedJUnit5Engine, expectedOpentest4j, expectedPlatformCommons, expectedEngine );
assertThat( testClasspathWrapper.getTestDependencies() )
- .hasSize( 2 )
- .includes( entry( "junit:junit", testClasspathJUnit ),
- entry( "org.hamcrest:hamcrest-core", testClasspathHamcrest ) );
+ .hasSize( 2 )
+ .includes( entry( "junit:junit", testClasspathJUnit ),
+ entry( "org.hamcrest:hamcrest-core", testClasspathHamcrest ) );
}
@Test
@@ -983,38 +984,38 @@ public void shouldSmartlyResolveJUnit5ProviderWithVintage() throws Exception
{
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
VersionRange surefireVersion = createFromVersion( "1" );
Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
- createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathVintage = new DefaultArtifact( "org.junit.vintage", "junit-vintage-engine",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
- createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathPlatformEng = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathJUnit4 = new DefaultArtifact( "junit", "junit",
- createFromVersion( "4.12" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "4.12" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathHamcrest = new DefaultArtifact( "org.hamcrest", "hamcrest-core",
- createFromVersion( "1.3" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.3" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathOpentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathCommons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Collection testArtifacts = asList( testClasspathSomeTestArtifact, testClasspathVintage,
- testClasspathApiguardian, testClasspathPlatformEng, testClasspathJUnit4, testClasspathHamcrest,
- testClasspathOpentest4j, testClasspathCommons );
+ testClasspathApiguardian, testClasspathPlatformEng, testClasspathJUnit4, testClasspathHamcrest,
+ testClasspathOpentest4j, testClasspathCommons );
setProjectDepedenciesToMojo( testArtifacts.toArray( new Artifact[testArtifacts.size()] ) );
@@ -1023,13 +1024,13 @@ public void shouldSmartlyResolveJUnit5ProviderWithVintage() throws Exception
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer()
{
@Override
@@ -1043,43 +1044,43 @@ public Artifact answer( InvocationOnMock invocation )
} );
final ArtifactResolutionResult surefireProviderResolutionResult = mock( ArtifactResolutionResult.class );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact resolvable = req.getArtifact();
+ if ( resolvable == surefireProvider )
+ {
+ return surefireProviderResolutionResult;
+ }
+ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
+ && "junit-platform-launcher".equals( resolvable.getArtifactId() )
+ && "1.4.0".equals( resolvable.getVersion() ) )
+ {
+ return createExpectedJUnitPlatformLauncherResolutionResult();
+ }
+ else
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact resolvable = req.getArtifact();
- if ( resolvable == surefireProvider )
- {
- return surefireProviderResolutionResult;
- }
- else if ( "org.junit.platform".equals( resolvable.getGroupId() )
- && "junit-platform-launcher".equals( resolvable.getArtifactId() )
- && "1.4.0".equals( resolvable.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else
- {
- fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
- return null;
- }
+ fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
+ return null;
}
- } );
+ }
+ } );
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Set providerArtifacts = new HashSet<>();
providerArtifacts.add( surefireProvider );
providerArtifacts.add( java5 );
@@ -1089,7 +1090,7 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
providerArtifacts.add( commons );
providerArtifacts.add( opentest4j );
when( surefireProviderResolutionResult.getArtifacts() )
- .thenReturn( providerArtifacts );
+ .thenReturn( providerArtifacts );
mojo.setRepositorySystem( repositorySystem );
mojo.setLogger( mock( Logger.class ) );
@@ -1110,31 +1111,31 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
Artifact expectedProvider = new DefaultArtifact( "org.apache.maven.surefire", "surefire-junit-platform",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedCommonJava5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact expectedLauncher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( prov.getProviderClasspath() )
- .hasSize( 3 )
- .containsOnly( expectedProvider, expectedCommonJava5, expectedLauncher );
+ .hasSize( 3 )
+ .containsOnly( expectedProvider, expectedCommonJava5, expectedLauncher );
assertThat( testClasspathWrapper.getTestDependencies() )
- .hasSize( 8 )
- .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
- entry( "org.junit.vintage:junit-vintage-engine", testClasspathVintage ),
- entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
- entry( "org.junit.platform:junit-platform-engine", testClasspathPlatformEng ),
- entry( "junit:junit", testClasspathJUnit4 ),
- entry( "org.hamcrest:hamcrest-core", testClasspathHamcrest ),
- entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ),
- entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ) );
+ .hasSize( 8 )
+ .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+ entry( "org.junit.vintage:junit-vintage-engine", testClasspathVintage ),
+ entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
+ entry( "org.junit.platform:junit-platform-engine", testClasspathPlatformEng ),
+ entry( "junit:junit", testClasspathJUnit4 ),
+ entry( "org.hamcrest:hamcrest-core", testClasspathHamcrest ),
+ entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ),
+ entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ) );
}
@Test
@@ -1142,22 +1143,22 @@ public void shouldSmartlyResolveJUnit5ProviderWithJUnit5Commons() throws Excepti
{
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
final VersionRange surefireVersion = createFromVersion( "1" );
Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
- createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathCommons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact testClasspathApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
- createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Collection testArtifacts =
- asList( testClasspathSomeTestArtifact, testClasspathApiguardian, testClasspathCommons );
+ asList( testClasspathSomeTestArtifact, testClasspathApiguardian, testClasspathCommons );
setProjectDepedenciesToMojo( testArtifacts.toArray( new Artifact[testArtifacts.size()] ) );
@@ -1166,13 +1167,13 @@ public void shouldSmartlyResolveJUnit5ProviderWithJUnit5Commons() throws Excepti
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer()
{
@Override
@@ -1186,30 +1187,30 @@ public Artifact answer( InvocationOnMock invocation )
} );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact resolvable = req.getArtifact();
+ if ( resolvable == surefireProvider )
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact resolvable = req.getArtifact();
- if ( resolvable == surefireProvider )
- {
- return createSurefireProviderResolutionResult( surefireVersion );
- }
- else if ( "org.junit.platform".equals( resolvable.getGroupId() )
- && "junit-platform-launcher".equals( resolvable.getArtifactId() )
- && "1.4.0".equals( resolvable.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else
- {
- fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
- return null;
- }
+ return createSurefireProviderResolutionResult( surefireVersion );
}
- } );
+ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
+ && "junit-platform-launcher".equals( resolvable.getArtifactId() )
+ && "1.4.0".equals( resolvable.getVersion() ) )
+ {
+ return createExpectedJUnitPlatformLauncherResolutionResult();
+ }
+ else
+ {
+ fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
+ return null;
+ }
+ }
+ } );
mojo.setRepositorySystem( repositorySystem );
mojo.setLogger( mock( Logger.class ) );
@@ -1217,15 +1218,15 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
invokeMethod( mojo, "setupStuff" );
when( mojo.getSession().getProjectBuildingRequest() )
- .thenReturn( mock( ProjectBuildingRequest.class ) );
+ .thenReturn( mock( ProjectBuildingRequest.class ) );
PluginDescriptor pluginDescriptor = mock( PluginDescriptor.class );
mojo.setPluginDescriptor( pluginDescriptor );
Plugin p = mock( Plugin.class );
when( pluginDescriptor.getPlugin() )
- .thenReturn( p );
+ .thenReturn( p );
when( p.getDependencies() )
- .thenReturn( Collections.emptyList() );
+ .thenReturn( Collections.emptyList() );
Artifact junitPlatformArtifact = invokeMethod( mojo, "getJUnit5Artifact" );
assertThat( junitPlatformArtifact.getGroupId() ).isEqualTo( "org.junit.platform" );
@@ -1233,7 +1234,7 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
@@ -1241,24 +1242,24 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
Set resolvedProviderArtifacts = prov.getProviderClasspath();
Artifact provider = new DefaultArtifact( "org.apache.maven.surefire", "surefire-junit-platform",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact engine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( resolvedProviderArtifacts )
- .hasSize( 5 )
- .containsOnly( provider, java5, launcher, engine, opentest4j );
+ .hasSize( 5 )
+ .containsOnly( provider, java5, launcher, engine, opentest4j );
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 ) );
+ .hasSize( 3 )
+ .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+ entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
+ entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ) );
}
@Test
@@ -1266,28 +1267,28 @@ public void shouldSmartlyResolveJUnit5ProviderWithJUnit5Engine() throws Exceptio
{
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
final VersionRange surefireVersion = createFromVersion( "1" );
final Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
- createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ 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, 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 ) );
+ 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", null, 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Collection testArtifacts = asList( testClasspathSomeTestArtifact, testClasspathJUnit5,
- testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
+ testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
setProjectDepedenciesToMojo( testArtifacts.toArray( new Artifact[testArtifacts.size()] ) );
@@ -1296,13 +1297,13 @@ public void shouldSmartlyResolveJUnit5ProviderWithJUnit5Engine() throws Exceptio
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer()
{
@Override
@@ -1316,30 +1317,30 @@ public Artifact answer( InvocationOnMock invocation )
} );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact resolvable = req.getArtifact();
+ if ( resolvable == surefireProvider )
+ {
+ return createSurefireProviderResolutionResult( surefireVersion );
+ }
+ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
+ && "junit-platform-launcher".equals( resolvable.getArtifactId() )
+ && "1.4.0".equals( resolvable.getVersion() ) )
+ {
+ return createExpectedJUnitPlatformLauncherResolutionResult();
+ }
+ else
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact resolvable = req.getArtifact();
- if ( resolvable == surefireProvider )
- {
- return createSurefireProviderResolutionResult( surefireVersion );
- }
- else if ( "org.junit.platform".equals( resolvable.getGroupId() )
- && "junit-platform-launcher".equals( resolvable.getArtifactId() )
- && "1.4.0".equals( resolvable.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else
- {
- fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
- return null;
- }
+ fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
+ return null;
}
- } );
+ }
+ } );
mojo.setRepositorySystem( repositorySystem );
mojo.setLogger( mock( Logger.class ) );
@@ -1352,7 +1353,7 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
@@ -1360,20 +1361,20 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
Set resolvedProviderArtifacts = prov.getProviderClasspath();
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( resolvedProviderArtifacts )
- .hasSize( 3 )
- .containsOnly( surefireProvider, java5, launcher );
+ .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 ) );
+ .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 ) );
}
@Test
@@ -1381,28 +1382,28 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterApi() throws Exception
{
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
final VersionRange surefireVersion = createFromVersion( "1" );
final Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
- createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact testClasspathJupiterApi = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-api",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.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 ) );
+ 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", null, 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Collection testArtifacts = asList( testClasspathSomeTestArtifact, testClasspathJupiterApi,
- testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
+ testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
setProjectDepedenciesToMojo( testArtifacts.toArray( new Artifact[testArtifacts.size()] ) );
@@ -1411,13 +1412,13 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterApi() throws Exception
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer()
{
@Override
@@ -1431,36 +1432,36 @@ public Artifact answer( InvocationOnMock invocation )
} );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact resolvable = req.getArtifact();
+ if ( resolvable == surefireProvider )
+ {
+ return createSurefireProviderResolutionResult( surefireVersion );
+ }
+ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
+ && "junit-platform-launcher".equals( resolvable.getArtifactId() )
+ && "1.4.0".equals( resolvable.getVersion() ) )
+ {
+ return createExpectedJUnitPlatformLauncherResolutionResult();
+ }
+ else if ( "org.junit.jupiter".equals( resolvable.getGroupId() )
+ && "junit-jupiter-engine".equals( resolvable.getArtifactId() )
+ && "5.4.0".equals( resolvable.getVersion() ) )
+ {
+ return createJupiterEngineResolutionResult();
+ }
+ else
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact resolvable = req.getArtifact();
- if ( resolvable == surefireProvider )
- {
- return createSurefireProviderResolutionResult( surefireVersion );
- }
- else if ( "org.junit.platform".equals( resolvable.getGroupId() )
- && "junit-platform-launcher".equals( resolvable.getArtifactId() )
- && "1.4.0".equals( resolvable.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else if ( "org.junit.jupiter".equals( resolvable.getGroupId() )
- && "junit-jupiter-engine".equals( resolvable.getArtifactId() )
- && "5.4.0".equals( resolvable.getVersion() ) )
- {
- return createJupiterEngineResolutionResult();
- }
- else
- {
- fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
- return null;
- }
+ fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
+ return null;
}
- } );
+ }
+ } );
mojo.setRepositorySystem( repositorySystem );
mojo.setLogger( mock( Logger.class ) );
@@ -1468,15 +1469,15 @@ else if ( "org.junit.jupiter".equals( resolvable.getGroupId() )
invokeMethod( mojo, "setupStuff" );
when( mojo.getSession().getProjectBuildingRequest() )
- .thenReturn( mock( ProjectBuildingRequest.class ) );
+ .thenReturn( mock( ProjectBuildingRequest.class ) );
PluginDescriptor pluginDescriptor = mock( PluginDescriptor.class );
mojo.setPluginDescriptor( pluginDescriptor );
Plugin p = mock( Plugin.class );
when( pluginDescriptor.getPlugin() )
- .thenReturn( p );
+ .thenReturn( p );
when( p.getDependencies() )
- .thenReturn( Collections.emptyList() );
+ .thenReturn( Collections.emptyList() );
Artifact junitPlatformArtifact = invokeMethod( mojo, "getJUnit5Artifact" );
assertThat( junitPlatformArtifact.getGroupId() ).isEqualTo( "org.junit.platform" );
@@ -1484,7 +1485,7 @@ else if ( "org.junit.jupiter".equals( resolvable.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
@@ -1492,24 +1493,24 @@ else if ( "org.junit.jupiter".equals( resolvable.getGroupId() )
Set resolvedProviderArtifacts = prov.getProviderClasspath();
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact jupiterEngine = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-engine",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact platformEngine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( resolvedProviderArtifacts )
- .hasSize( 5 )
- .containsOnly( surefireProvider, java5, launcher, jupiterEngine, platformEngine );
+ .hasSize( 5 )
+ .containsOnly( surefireProvider, java5, launcher, jupiterEngine, platformEngine );
assertThat( testClasspathWrapper.getTestDependencies() )
- .hasSize( 5 )
- .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
- entry( "org.junit.jupiter:junit-jupiter-api", testClasspathJupiterApi ),
- entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
- entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
- entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
+ .hasSize( 5 )
+ .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+ entry( "org.junit.jupiter:junit-jupiter-api", testClasspathJupiterApi ),
+ entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
+ entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
+ entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
}
@Test
@@ -1517,35 +1518,35 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterEngine() throws Excepti
{
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
final VersionRange surefireVersion = createFromVersion( "1" );
final Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
- createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact testClasspathJupiterEngine = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-engine",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact testClasspathPlatformEngine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact testClasspathJupiterApi = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-api",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.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 ) );
+ 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", null, 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Collection testArtifacts = asList( testClasspathSomeTestArtifact, testClasspathJupiterEngine,
- testClasspathPlatformEngine, testClasspathJupiterApi, testClasspathApiguardian, testClasspathCommons,
- testClasspathOpentest4j );
+ testClasspathPlatformEngine, testClasspathJupiterApi, testClasspathApiguardian, testClasspathCommons,
+ testClasspathOpentest4j );
setProjectDepedenciesToMojo( testArtifacts.toArray( new Artifact[testArtifacts.size()] ) );
@@ -1554,13 +1555,13 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterEngine() throws Excepti
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer()
{
@Override
@@ -1574,30 +1575,30 @@ public Artifact answer( InvocationOnMock invocation )
} );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact resolvable = req.getArtifact();
+ if ( resolvable == surefireProvider )
+ {
+ return createSurefireProviderResolutionResult( surefireVersion );
+ }
+ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
+ && "junit-platform-launcher".equals( resolvable.getArtifactId() )
+ && "1.4.0".equals( resolvable.getVersion() ) )
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact resolvable = req.getArtifact();
- if ( resolvable == surefireProvider )
- {
- return createSurefireProviderResolutionResult( surefireVersion );
- }
- else if ( "org.junit.platform".equals( resolvable.getGroupId() )
- && "junit-platform-launcher".equals( resolvable.getArtifactId() )
- && "1.4.0".equals( resolvable.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else
- {
- fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
- return null;
- }
+ return createExpectedJUnitPlatformLauncherResolutionResult();
}
- } );
+ else
+ {
+ fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
+ return null;
+ }
+ }
+ } );
mojo.setRepositorySystem( repositorySystem );
mojo.setLogger( mock( Logger.class ) );
@@ -1610,7 +1611,7 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
@@ -1618,22 +1619,22 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
Set resolvedProviderArtifacts = prov.getProviderClasspath();
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( resolvedProviderArtifacts )
- .hasSize( 3 )
- .containsOnly( surefireProvider, java5, launcher );
+ .hasSize( 3 )
+ .containsOnly( surefireProvider, java5, launcher );
assertThat( testClasspathWrapper.getTestDependencies() )
- .hasSize( 7 )
- .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
- entry( "org.junit.jupiter:junit-jupiter-engine", testClasspathJupiterEngine ),
- entry( "org.junit.platform:junit-platform-engine", testClasspathPlatformEngine ),
- entry( "org.junit.jupiter:junit-jupiter-api", testClasspathJupiterApi ),
- entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
- entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
- entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
+ .hasSize( 7 )
+ .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+ entry( "org.junit.jupiter:junit-jupiter-engine", testClasspathJupiterEngine ),
+ entry( "org.junit.platform:junit-platform-engine", testClasspathPlatformEngine ),
+ entry( "org.junit.jupiter:junit-jupiter-api", testClasspathJupiterApi ),
+ entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
+ entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
+ entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
}
@Test
@@ -1642,28 +1643,28 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterEngineInPluginDependenc
final VersionRange surefireVersion = createFromVersion( "1" );
final Artifact plugin = new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-plugin",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact forkedBooter = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-booter", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-booter", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDepJupiterEngine = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-engine",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDepPlatformEngine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDepJupiterApi = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-api",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDepApiguardian = new DefaultArtifact( "org.apiguardian", "apiguardian-api",
- createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDepCommons = new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact pluginDepOpentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
mojo.getPluginArtifactMap().put( "org.apache.maven.surefire:maven-surefire-plugin", plugin );
mojo.getPluginArtifactMap().put( "org.apache.maven.surefire:surefire-booter", forkedBooter );
@@ -1676,26 +1677,26 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterEngineInPluginDependenc
MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "dummy", "pom", createFromVersion( "1.0.0" ),
- null, "jar", null, mock( ArtifactHandler.class ) ) );
+ null, "jar", null, mock( ArtifactHandler.class ) ) );
mojo.setProject( mavenProject );
final Artifact testClasspathSomeTestArtifact = new DefaultArtifact( "third.party", "artifact",
- createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
final Artifact testClasspathJupiterApi = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-api",
- createFromVersion( "5.3.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.3.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 ) );
+ 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", null, 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Collection testArtifacts = asList( testClasspathSomeTestArtifact, testClasspathJupiterApi,
- testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
+ testClasspathApiguardian, testClasspathCommons, testClasspathOpentest4j );
setProjectDepedenciesToMojo( testArtifacts.toArray( new Artifact[testArtifacts.size()] ) );
@@ -1704,14 +1705,14 @@ public void shouldSmartlyResolveJUnit5ProviderWithJupiterEngineInPluginDependenc
File testClassesDirectory = new File( "target/test-classes" );
TestClassPath testClasspathWrapper =
- new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
+ new TestClassPath( testArtifacts, classesDirectory, testClassesDirectory, null );
mojo.setRemoteRepositories( Collections.emptyList() );
mojo.setProjectRemoteRepositories( Collections.emptyList() );
RepositorySystem repositorySystem = mock( RepositorySystem.class );
final Artifact surefireProvider = new DefaultArtifact( "org.apache.maven.surefire",
- "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ "surefire-junit-platform", surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( new Answer()
{
@Override
@@ -1737,34 +1738,34 @@ else if ( dependency.getArtifactId().equals( "junit-jupiter-engine" ) )
final ArtifactResolutionResult pluginDepJupiterEngineResolutionResult = mock( ArtifactResolutionResult.class );
when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) )
- .thenAnswer( new Answer()
+ .thenAnswer( new Answer()
+ {
+ @Override
+ public ArtifactResolutionResult answer( InvocationOnMock invocation )
{
- @Override
- public ArtifactResolutionResult answer( InvocationOnMock invocation )
+ ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
+ Artifact resolvable = req.getArtifact();
+ if ( resolvable == surefireProvider )
+ {
+ return createSurefireProviderResolutionResult( surefireVersion );
+ }
+ else if ( resolvable == pluginDepJupiterEngine )
{
- ArtifactResolutionRequest req = (ArtifactResolutionRequest) invocation.getArguments()[0];
- Artifact resolvable = req.getArtifact();
- if ( resolvable == surefireProvider )
- {
- return createSurefireProviderResolutionResult( surefireVersion );
- }
- else if ( resolvable == pluginDepJupiterEngine )
- {
- return pluginDepJupiterEngineResolutionResult;
- }
- else if ( "org.junit.platform".equals( resolvable.getGroupId() )
- && "junit-platform-launcher".equals( resolvable.getArtifactId() )
- && "1.4.0".equals( resolvable.getVersion() ) )
- {
- return createExpectedJUnitPlatformLauncherResolutionResult();
- }
- else
- {
- fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
- return null;
- }
+ return pluginDepJupiterEngineResolutionResult;
}
- } );
+ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
+ && "junit-platform-launcher".equals( resolvable.getArtifactId() )
+ && "1.4.0".equals( resolvable.getVersion() ) )
+ {
+ return createExpectedJUnitPlatformLauncherResolutionResult();
+ }
+ else
+ {
+ fail( resolvable.getGroupId() + ":" + resolvable.getArtifactId() );
+ return null;
+ }
+ }
+ } );
mojo.setRepositorySystem( repositorySystem );
mojo.setLogger( mock( Logger.class ) );
@@ -1787,44 +1788,44 @@ else if ( "org.junit.platform".equals( resolvable.getGroupId() )
assertThat( junitPlatformArtifact.getVersion() ).isEqualTo( "1.4.0" );
JUnitPlatformProviderInfo prov =
- mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
+ mojo.createJUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
assertThat( prov.isApplicable() )
.isTrue();
when( mojo.getSession().getProjectBuildingRequest() )
- .thenReturn( mock( ProjectBuildingRequest.class ) );
+ .thenReturn( mock( ProjectBuildingRequest.class ) );
PluginDescriptor pluginDescriptor = mock( PluginDescriptor.class );
mojo.setPluginDescriptor( pluginDescriptor );
Plugin p = mock( Plugin.class );
when( pluginDescriptor.getPlugin() )
- .thenReturn( p );
+ .thenReturn( p );
List directPluginDependencies = toDependencies( pluginDepJupiterEngine );
when( p.getDependencies() )
- .thenReturn( directPluginDependencies );
+ .thenReturn( directPluginDependencies );
Set resolvedProviderArtifacts = prov.getProviderClasspath();
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact jupiterEngine = new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-engine",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact platformEngine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
assertThat( resolvedProviderArtifacts )
- .hasSize( 5 )
- .containsOnly( surefireProvider, java5, launcher, jupiterEngine, platformEngine );
+ .hasSize( 5 )
+ .containsOnly( surefireProvider, java5, launcher, jupiterEngine, platformEngine );
assertThat( testClasspathWrapper.getTestDependencies() )
- .hasSize( 5 )
- .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
- entry( "org.junit.jupiter:junit-jupiter-api", testClasspathJupiterApi ),
- entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
- entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
- entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
+ .hasSize( 5 )
+ .includes( entry( "third.party:artifact", testClasspathSomeTestArtifact ),
+ entry( "org.junit.jupiter:junit-jupiter-api", testClasspathJupiterApi ),
+ entry( "org.apiguardian:apiguardian-api", testClasspathApiguardian ),
+ entry( "org.junit.platform:junit-platform-commons", testClasspathCommons ),
+ entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
}
@Test
@@ -1841,24 +1842,24 @@ public void shouldConvertJunitEngineParameters() throws Exception
invokeMethod( mojo, "convertJunitEngineParameters" );
assertThat( properties ).isEmpty();
- mojo.setIncludeJUnit5Engines( new String[] { "e1", "e2" } );
+ mojo.setIncludeJUnit5Engines( new String[] {"e1", "e2"} );
invokeMethod( mojo, "convertJunitEngineParameters" );
assertThat( properties )
.includes( entry( "includejunit5engines", "e1,e2" ) );
- mojo.setExcludeJUnit5Engines( new String[] { "e1", "e2" } );
+ mojo.setExcludeJUnit5Engines( new String[] {"e1", "e2"} );
invokeMethod( mojo, "convertJunitEngineParameters" );
assertThat( properties )
.includes( entry( "excludejunit5engines", "e1,e2" ) );
}
private static ArtifactResolutionResult createJUnitPlatformLauncherResolutionResult(
- Artifact junit5Engine, Artifact apiguardian, Artifact commons, Artifact opentest4j )
+ Artifact junit5Engine, Artifact apiguardian, Artifact commons, Artifact opentest4j )
{
ArtifactResolutionResult launcherResolutionResult = mock( ArtifactResolutionResult.class );
Set resolvedLauncherArtifacts = new HashSet<>();
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- commons.getVersionRange(), null, "jar", null, mock( ArtifactHandler.class ) );
+ commons.getVersionRange(), null, "jar", null, mock( ArtifactHandler.class ) );
resolvedLauncherArtifacts.add( launcher );
resolvedLauncherArtifacts.add( apiguardian );
resolvedLauncherArtifacts.add( junit5Engine );
@@ -1866,7 +1867,7 @@ private static ArtifactResolutionResult createJUnitPlatformLauncherResolutionRes
resolvedLauncherArtifacts.add( opentest4j );
resolvedLauncherArtifacts.remove( null );
when( launcherResolutionResult.getArtifacts() )
- .thenReturn( resolvedLauncherArtifacts );
+ .thenReturn( resolvedLauncherArtifacts );
return launcherResolutionResult;
}
@@ -1875,32 +1876,32 @@ private static ArtifactResolutionResult createJupiterEngineResolutionResult()
ArtifactResolutionResult launcherResolutionResult = mock( ArtifactResolutionResult.class );
Set resolvedLauncherArtifacts = new HashSet<>();
resolvedLauncherArtifacts.add( new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-engine",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
resolvedLauncherArtifacts.add( new DefaultArtifact( "org.junit.jupiter", "junit-jupiter-api",
- createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
+ createFromVersion( "5.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
resolvedLauncherArtifacts.add( new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
resolvedLauncherArtifacts.add( new DefaultArtifact( "org.apiguardian", "apiguardian-api",
- createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
+ createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
resolvedLauncherArtifacts.add( new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
resolvedLauncherArtifacts.add( new DefaultArtifact( "org.junit.platform", "junit-platform-commons",
- createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
+ createFromVersion( "1.4.0" ), null, "jar", null, mock( ArtifactHandler.class ) ) );
when( launcherResolutionResult.getArtifacts() )
- .thenReturn( resolvedLauncherArtifacts );
+ .thenReturn( resolvedLauncherArtifacts );
return launcherResolutionResult;
}
private static ArtifactResolutionResult createExpectedJUnitPlatformLauncherResolutionResult()
{
Artifact engine = new DefaultArtifact( "org.junit.platform", "junit-platform-engine",
- createFromVersion( "1.4.0" ), null, "jar", null, 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", null, 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.0.0" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
return createJUnitPlatformLauncherResolutionResult( engine, apiguardian, commons, opentest4j );
}
@@ -1909,19 +1910,19 @@ private static ArtifactResolutionResult createSurefireProviderResolutionResult(
ArtifactResolutionResult surefirePlatformResolutionResult = mock( ArtifactResolutionResult.class );
Artifact provider = new DefaultArtifact( "org.apache.maven.surefire", "surefire-junit-platform",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact java5 = new DefaultArtifact( "org.apache.maven.surefire", "common-java5",
- surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
+ surefireVersion, null, "jar", null, mock( ArtifactHandler.class ) );
Artifact launcher = new DefaultArtifact( "org.junit.platform", "junit-platform-launcher",
- createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ 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, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.3.2" ), null, "jar", null, mock( ArtifactHandler.class ) );
Artifact opentest4j = new DefaultArtifact( "org.opentest4j", "opentest4j",
- createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
+ createFromVersion( "1.1.1" ), null, "jar", null, mock( ArtifactHandler.class ) );
Set providerArtifacts = new HashSet<>();
providerArtifacts.add( provider );
@@ -1933,7 +1934,7 @@ private static ArtifactResolutionResult createSurefireProviderResolutionResult(
providerArtifacts.add( opentest4j );
when( surefirePlatformResolutionResult.getArtifacts() )
- .thenReturn( providerArtifacts );
+ .thenReturn( providerArtifacts );
return surefirePlatformResolutionResult;
}
@@ -1982,7 +1983,7 @@ private void addPluginDependencies( Artifact... deps )
*
*/
public static class Mojo
- extends AbstractSurefireMojo implements SurefireReportParameters
+ extends AbstractSurefireMojo implements SurefireReportParameters
{
private File mainBuildPath;
private File testClassesDirectory;
@@ -2409,7 +2410,7 @@ protected ForkNodeFactory getForkNode()
protected Artifact getMojoArtifact()
{
return new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-plugin", createFromVersion( "1" ),
- null, "jar", null, mock( ArtifactHandler.class ) );
+ null, "jar", null, mock( ArtifactHandler.class ) );
}
@Override
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/providerapi/ProviderDetectorTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/providerapi/ProviderDetectorTest.java
new file mode 100644
index 0000000000..5cc6143f82
--- /dev/null
+++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/providerapi/ProviderDetectorTest.java
@@ -0,0 +1,203 @@
+package org.apache.maven.surefire.providerapi;
+
+/*
+ * 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 java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.maven.surefire.api.provider.SurefireProvider;
+import org.codehaus.plexus.logging.Logger;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static java.util.Arrays.asList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+
+/**
+ * Unit test for ProviderDetector.
+ *
+ * @author Slawomir Jaranowski
+ */
+@RunWith( MockitoJUnitRunner.class )
+public class ProviderDetectorTest
+{
+
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private Logger logger;
+
+ @InjectMocks
+ private ProviderDetector providerDetector;
+
+ @Test
+ public void emptyProviderList() throws Exception
+ {
+ // given
+ ProviderInfo providerInfo1 = mock( ProviderInfo.class );
+ ProviderInfo providerInfo2 = mock( ProviderInfo.class );
+
+ // no manually configured providers
+ when( serviceLoader.lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) ) )
+ .thenReturn( Collections.emptySet() );
+
+ // all well known providers are not applicable
+ when( providerInfo1.isApplicable() ).thenReturn( false );
+ when( providerInfo2.isApplicable() ).thenReturn( false );
+
+ // when
+ List providerInfoList = providerDetector.resolve( null, providerInfo1, providerInfo2 );
+
+ // then
+ assertThat( providerInfoList ).isEmpty();
+
+ verify( serviceLoader ).lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) );
+
+ verify( providerInfo1 ).isApplicable();
+ verify( providerInfo2 ).isApplicable();
+
+ verifyNoMoreInteractions( logger, serviceLoader, providerInfo1, providerInfo2 );
+ }
+
+ @Test
+ public void onlyFirstAutomaticallyProviderIsReturned() throws Exception
+ {
+ // given
+ ProviderInfo providerInfo1 = mock( ProviderInfo.class );
+ ProviderInfo providerInfo2 = mock( ProviderInfo.class );
+
+ // no manually configured providers
+ when( serviceLoader.lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) ) )
+ .thenReturn( Collections.emptySet() );
+
+ // first well known providers are applicable
+ when( providerInfo1.isApplicable() ).thenReturn( true );
+
+ // when
+ List providerInfoList = providerDetector.resolve( null, providerInfo1, providerInfo2 );
+
+ // then - only first is returned
+ assertThat( providerInfoList ).containsExactly( providerInfo1 );
+
+ verify( serviceLoader ).lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) );
+
+ verify( providerInfo1 ).isApplicable();
+ verify( providerInfo1 ).getProviderName();
+
+ // second provider is not checked
+ verify( providerInfo2, never() ).isApplicable();
+
+ verify( logger ).info( anyString() );
+
+ verifyNoMoreInteractions( logger, serviceLoader, providerInfo1, providerInfo2 );
+ }
+
+ @Test
+ public void allManuallyConfiguredProviderAreReturned() throws IOException
+ {
+ // given
+ ProviderInfo providerInfo1 = mock( ProviderInfo.class );
+ ProviderInfo providerInfo2 = mock( ProviderInfo.class );
+
+ // manually configured providers
+ when( serviceLoader.lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) ) )
+ .thenReturn( new HashSet<>( asList( "provider1", "provider2" ) ) );
+
+ when( providerInfo1.getProviderName() ).thenReturn( "provider1" );
+ when( providerInfo2.getProviderName() ).thenReturn( "provider2" );
+
+ // when
+ List providerInfoList = providerDetector.resolve( null, providerInfo1, providerInfo2 );
+
+ // then - all providers on list
+ assertThat( providerInfoList ).containsExactly( providerInfo1, providerInfo2 );
+
+ verify( serviceLoader ).lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) );
+
+ verify( providerInfo1, times( 3 ) ).getProviderName();
+ verify( providerInfo2, times( 2 ) ).getProviderName();
+
+ // don't check - if it should be used ???
+ verify( providerInfo1, never() ).isApplicable();
+ verify( providerInfo1, never() ).isApplicable();
+
+ verify( logger, times( 2 ) ).info( anyString() );
+
+ verifyNoMoreInteractions( logger, serviceLoader, providerInfo1, providerInfo2 );
+ }
+
+ @Test
+ public void dynamicallyProviderAreReturned() throws IOException
+ {
+ // given
+ ProviderInfo providerInfo1 = mock( ProviderInfo.class );
+ ProviderInfo providerInfo2 = mock( ProviderInfo.class );
+ ProviderInfo dynProviderInfo = mock( ProviderInfo.class );
+
+ ConfigurableProviderInfo dynamicProvider = mock( ConfigurableProviderInfo.class );
+
+ // manually configured providers
+ when( serviceLoader.lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) ) )
+ .thenReturn( new HashSet<>( asList( "unKnown", "provider2" ) ) );
+
+ when( dynamicProvider.instantiate( anyString() ) ).thenReturn( dynProviderInfo );
+
+ when( providerInfo1.getProviderName() ).thenReturn( "provider1" );
+ when( providerInfo2.getProviderName() ).thenReturn( "provider2" );
+
+ // when
+ List providerInfoList = providerDetector.resolve( dynamicProvider, providerInfo1, providerInfo2 );
+
+ // then - all providers on list
+ assertThat( providerInfoList ).containsExactly( dynProviderInfo, providerInfo2 );
+
+ verify( serviceLoader ).lookup( eq( SurefireProvider.class ), any( ClassLoader.class ) );
+
+ verify( dynamicProvider ).instantiate( "unKnown" );
+
+ verify( providerInfo1, times( 2 ) ).getProviderName();
+ verify( providerInfo2, times( 3 ) ).getProviderName();
+
+ // don't check - if it should be used ???
+ verify( providerInfo1, never() ).isApplicable();
+ verify( dynamicProvider, never() ).isApplicable();
+
+ verify( logger, times( 2 ) ).info( anyString() );
+
+ verifyNoMoreInteractions( logger, serviceLoader, dynamicProvider, providerInfo1, providerInfo2 );
+ }
+
+}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/spi/SPITest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/spi/SPITest.java
index 2d00799e09..48ee1be7f0 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/spi/SPITest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/spi/SPITest.java
@@ -19,12 +19,11 @@
* under the License.
*/
-import org.apache.maven.plugin.surefire.booterclient.ProviderDetector;
+import java.io.IOException;
+
import org.apache.maven.surefire.providerapi.ServiceLoader;
import org.junit.Test;
-import java.io.IOException;
-
import static java.lang.Thread.currentThread;
import static org.fest.assertions.Assertions.assertThat;
@@ -35,56 +34,42 @@
public class SPITest
{
private final ServiceLoader spi = new ServiceLoader();
- private final ProviderDetector providerDetector = new ProviderDetector();
private final ClassLoader ctx = currentThread().getContextClassLoader();
@Test
public void shouldNotLoadSpiDoesNotExist() throws IOException
{
assertThat( spi.lookup( NoServiceInterface.class, ctx ) )
- .isEmpty();
+ .isEmpty();
assertThat( spi.load( NoServiceInterface.class, ctx ) )
- .isEmpty();
-
- assertThat( providerDetector.lookupServiceNames( NoServiceInterface.class, ctx ) )
- .isEmpty();
+ .isEmpty();
}
@Test
public void shouldNotLoadEmptySpi() throws IOException
{
assertThat( spi.lookup( EmptyServiceInterface.class, ctx ) )
- .isEmpty();
+ .isEmpty();
assertThat( spi.load( EmptyServiceInterface.class, ctx ) )
- .isEmpty();
-
- assertThat( providerDetector.lookupServiceNames( EmptyServiceInterface.class, ctx ) )
- .isEmpty();
+ .isEmpty();
}
@Test
public void shouldLoad2SpiObjects() throws IOException
{
assertThat( spi.lookup( ExistingServiceInterface.class, ctx ) )
- .hasSize( 2 );
+ .hasSize( 2 );
assertThat( spi.lookup( ExistingServiceInterface.class, ctx ) )
- .containsOnly( SPImpl1.class.getName(), SPImpl2.class.getName() );
+ .containsOnly( SPImpl1.class.getName(), SPImpl2.class.getName() );
assertThat( spi.load( ExistingServiceInterface.class, ctx ) )
- .hasSize( 2 );
+ .hasSize( 2 );
assertThat( spi.load( ExistingServiceInterface.class, ctx ) )
- .contains( new SPImpl1(), new SPImpl2() );
-
-
- assertThat( providerDetector.lookupServiceNames( ExistingServiceInterface.class, ctx ) )
- .hasSize( 2 );
-
- assertThat( providerDetector.lookupServiceNames( ExistingServiceInterface.class, ctx ) )
- .containsOnly( SPImpl1.class.getName(), SPImpl2.class.getName() );
+ .contains( new SPImpl1(), new SPImpl2() );
}
}