From 48fc10889ef89d12ebe2258029937010d81aebb7 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 12 Feb 2021 17:21:59 +0100 Subject: [PATCH] [MNG-7077] Use JUnit 5 extension Signed-off-by: rfscholte --- .../AbstractArtifactComponentTestCase.java | 17 +- .../deployer/ArtifactDeployerTest.java | 1 + .../factory/DefaultArtifactFactoryTest.java | 4 +- .../installer/ArtifactInstallerTest.java | 2 + .../resolver/ArtifactResolverTest.java | 10 - .../resolver/DefaultArtifactResolverTest.java | 11 +- .../transform/TransformationManagerTest.java | 4 +- .../manager/DefaultProfileManagerTest.java | 22 ++- .../project/AbstractMavenProjectTestCase.java | 38 ++-- .../maven/project/ProjectClasspathTest.java | 12 +- .../AbstractProjectInheritanceTestCase.java | 2 + .../LegacyRepositorySystemTest.java | 12 +- .../maven/repository/MirrorProcessorTest.java | 4 +- .../legacy/DefaultWagonManagerTest.java | 6 +- .../legacy/LegacyRepositorySystemTest.java | 4 +- .../DefaultArtifactCollectorTest.java | 7 +- .../AbstractConflictResolverTest.java | 29 +-- .../DefaultClasspathTransformationTest.java | 8 +- .../DefaultGraphConflictResolverTest.java | 8 +- .../AbstractCoreMavenComponentTestCase.java | 32 ++- .../org/apache/maven/DefaultMavenTest.java | 2 +- .../maven/MavenLifecycleParticipantTest.java | 6 - .../ProjectDependenciesResolverTest.java | 1 + .../artifact/handler/ArtifactHandlerTest.java | 14 +- ...ultMavenExecutionRequestPopulatorTest.java | 5 +- .../maven/graph/DefaultGraphBuilderTest.java | 51 ++--- .../lifecycle/DefaultLifecyclesTest.java | 5 +- .../lifecycle/LifecycleExecutorTest.java | 8 +- ...luginParameterExpressionEvaluatorTest.java | 1 + .../project/AbstractMavenProjectTestCase.java | 24 +-- .../DefaultMavenProjectBuilderTest.java | 6 +- .../maven/project/PomConstructionTest.java | 15 +- .../maven/project/ProjectBuilderTest.java | 20 +- .../project/ProjectModelResolverTest.java | 5 +- .../artifact/MavenMetadataSourceTest.java | 44 +++-- .../DefaultRuntimeInformationTest.java | 13 +- .../PomConstructionWithSettingsTest.java | 6 +- .../internal/AbstractRepositoryTestCase.java | 18 +- .../DefaultArtifactDescriptorReaderTest.java | 2 +- .../internal/DefaultModelResolverTest.java | 4 +- .../java/org/apache/maven/test/Parameter.java | 32 --- .../maven/test/ParameterizedExtension.java | 182 ------------------ .../org/apache/maven/test/Parameters.java | 35 ---- ...exusTestCase.java => PlexusExtension.java} | 42 ++-- .../{Parameterized.java => PlexusTest.java} | 9 +- .../main/java/org/apache/maven/test/Test.java | 34 ---- .../xml/sax/ext/CommentRenormalizerTest.java | 31 +-- 47 files changed, 260 insertions(+), 588 deletions(-) delete mode 100644 maven-test-support/src/main/java/org/apache/maven/test/Parameter.java delete mode 100644 maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java delete mode 100644 maven-test-support/src/main/java/org/apache/maven/test/Parameters.java rename maven-test-support/src/main/java/org/apache/maven/test/{PlexusTestCase.java => PlexusExtension.java} (87%) rename maven-test-support/src/main/java/org/apache/maven/test/{Parameterized.java => PlexusTest.java} (87%) delete mode 100644 maven-test-support/src/main/java/org/apache/maven/test/Test.java diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 146ec685eb..0c6c062a25 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -32,7 +32,7 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Named; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; @@ -42,6 +42,7 @@ import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; +import org.codehaus.plexus.PlexusContainer; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.collection.DependencyGraphTransformer; @@ -67,14 +68,15 @@ import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Jason van Zyl */ -public abstract class AbstractArtifactComponentTestCase - extends PlexusTestCase +@PlexusTest +public abstract class AbstractArtifactComponentTestCase //extends PlexusTestCase { @Inject protected ArtifactFactory artifactFactory; @@ -88,12 +90,17 @@ public abstract class AbstractArtifactComponentTestCase @Inject @Named( "default" ) ArtifactRepositoryLayout repoLayout; + @Inject + PlexusContainer container; + + public PlexusContainer getContainer() { + return container; + } + @BeforeEach public void setUp() throws Exception { - super.setUp(); - RepositorySystemSession repoSession = initRepoSession(); MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult() ); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 05191ae684..e321e4579b 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -28,6 +28,7 @@ import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java index 6dcf99acb0..517bc71aa4 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java @@ -21,15 +21,15 @@ package org.apache.maven.artifact.factory; import javax.inject.Inject; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.VersionRange; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +@PlexusTest public class DefaultArtifactFactoryTest - extends PlexusTestCase { @Inject diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java index 695c5cc2e5..0010d4f41a 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java @@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test; import javax.inject.Inject; +import static org.apache.maven.test.PlexusExtension.getBasedir; + /** * @author Jason van Zyl */ diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index d621d906e9..6aa065297e 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -34,7 +34,6 @@ import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -71,15 +70,6 @@ public class ArtifactResolverTest projectArtifact = createLocalArtifact( "project", "3.0" ); } - @AfterEach - @Override - public void tearDown() - throws Exception - { - projectArtifact = null; - super.tearDown(); - } - @Override protected String component() { diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java index fdd5f62bcf..23e93be882 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java @@ -49,15 +49,6 @@ public class DefaultArtifactResolverTest projectArtifact = createLocalArtifact( "project", "3.0" ); } - @AfterEach - @Override - public void tearDown() - throws Exception - { - projectArtifact = null; - super.tearDown(); - } - @Override protected String component() { @@ -114,6 +105,6 @@ public class DefaultArtifactResolverTest public void testLookup() throws Exception { - ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" ); + ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "default" ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java index 5c1ae2d289..08e1055484 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java @@ -22,7 +22,7 @@ import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformat import org.apache.maven.repository.legacy.resolver.transform.LatestArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,8 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; /** @author Jason van Zyl */ +@PlexusTest public class TransformationManagerTest - extends PlexusTestCase { @Inject ArtifactTransformationManager tm; diff --git a/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java index 442493a64c..5c9dc6b4ee 100644 --- a/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java @@ -22,21 +22,32 @@ package org.apache.maven.profiles.manager; import java.util.List; import java.util.Properties; -import org.apache.maven.test.PlexusTestCase; +import javax.inject.Inject; + +import org.apache.maven.test.PlexusTest; import org.apache.maven.model.Activation; import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.Profile; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileManager; +import org.codehaus.plexus.PlexusContainer; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +@PlexusTest public class DefaultProfileManagerTest - extends PlexusTestCase { + @Inject + PlexusContainer container; + + protected PlexusContainer getContainer() { + return container; + } + @Test public void testShouldActivateDefaultProfile() throws Exception @@ -201,10 +212,13 @@ public class DefaultProfileManagerTest assertNotNull( active ); assertEquals( 0, active.size() ); } -/* + + @Test + @Disabled public void testOsActivationProfile() throws Exception { + /* Profile osActivated = new Profile(); osActivated.setId( "os-profile" ); @@ -229,7 +243,7 @@ public class DefaultProfileManagerTest assertNotNull( active ); assertEquals( 1, active.size() ); + */ } - */ } diff --git a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index 338cffa6a0..52f8dfe9a6 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -24,13 +24,14 @@ import java.util.Arrays; import javax.inject.Inject; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.codehaus.plexus.PlexusContainer; import org.eclipse.aether.DefaultRepositorySystemSession; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -40,54 +41,41 @@ import static org.junit.jupiter.api.Assertions.fail; /** * @author Jason van Zyl */ +@PlexusTest public abstract class AbstractMavenProjectTestCase - extends PlexusTestCase { protected ProjectBuilder projectBuilder; @Inject protected RepositorySystem repositorySystem; - @Override + @Inject + protected PlexusContainer container; + + public PlexusContainer getContainer() { + return container; + } + @BeforeEach public void setUp() throws Exception { - super.setUp(); - if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) { - projectBuilder = lookup( ProjectBuilder.class, "test" ); + projectBuilder = getContainer().lookup( ProjectBuilder.class, "test" ); } else { // default over to the main project builder... - projectBuilder = lookup( ProjectBuilder.class ); + projectBuilder = getContainer().lookup( ProjectBuilder.class ); } } - @AfterEach - public void tearDown() - throws Exception - { - projectBuilder = null; - - super.tearDown(); - } - protected ProjectBuilder getProjectBuilder() { return projectBuilder; } - @Override - protected String getCustomConfigurationName() - { - String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml"; - System.out.println( name ); - return name; - } - // ---------------------------------------------------------------------- // Local repository // ---------------------------------------------------------------------- @@ -118,7 +106,7 @@ public abstract class AbstractMavenProjectTestCase protected ArtifactRepository getLocalRepository() throws Exception { - ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class ); + ArtifactRepositoryLayout repoLayout = getContainer().lookup( ArtifactRepositoryLayout.class ); ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null ); diff --git a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index 0cc449f863..a2119cea53 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -44,17 +44,11 @@ public class ProjectClasspathTest { super.setUp(); - ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" ); - DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class); + ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "classpath" ); + DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)getContainer().lookup(ArtifactDescriptorReader.class); pomReader.setArtifactResolver( resolver ); - projectBuilder = lookup( ProjectBuilder.class, "classpath" ); - } - - @Override - protected String getCustomConfigurationName() - { - return null; + projectBuilder = getContainer().lookup( ProjectBuilder.class, "classpath" ); } @Test diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java index 93358ecc1f..2538abc0f4 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java @@ -23,6 +23,8 @@ import java.io.File; import org.apache.maven.project.AbstractMavenProjectTestCase; +import static org.apache.maven.test.PlexusExtension.getTestFile; + /** * @author Jason van Zyl */ diff --git a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java index eb56bc8590..85057832c9 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java @@ -32,7 +32,8 @@ import org.apache.maven.model.Repository; import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.repository.legacy.LegacyRepositorySystem; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; +import org.codehaus.plexus.PlexusContainer; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; @@ -40,6 +41,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -51,13 +53,15 @@ import javax.inject.Inject; * * @author Benjamin Bentmann */ +@PlexusTest public class LegacyRepositorySystemTest - extends PlexusTestCase { @Inject private RepositorySystem repositorySystem; @Inject private ResolutionErrorHandler resolutionErrorHandler; + @Inject + private PlexusContainer container; protected List getRemoteRepositories() throws Exception @@ -110,8 +114,8 @@ public class LegacyRepositorySystemTest DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(); LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() ); session.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( session, localRepo ) ); - LegacySupport legacySupport = lookup( LegacySupport.class ); - legacySupport.setSession( new MavenSession( getContainer(), session, new DefaultMavenExecutionRequest(), + LegacySupport legacySupport = container.lookup( LegacySupport.class ); + legacySupport.setSession( new MavenSession( container, session, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult() ) ); ArtifactResolutionResult result = repositorySystem.resolve( request ); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java index 443bc44135..49277ba024 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java @@ -22,7 +22,7 @@ package org.apache.maven.repository; import java.util.Arrays; import java.util.List; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; @@ -38,8 +38,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; +@PlexusTest public class MirrorProcessorTest - extends PlexusTestCase { @Inject private DefaultMirrorSelector mirrorSelector; diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index e6177c722a..eefe1b5afb 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -34,6 +34,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; +import org.apache.maven.test.PlexusTest; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.UnsupportedProtocolException; @@ -42,13 +43,14 @@ import org.apache.maven.wagon.events.TransferEvent; import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.observers.AbstractTransferListener; import org.apache.maven.wagon.observers.Debug; -import org.apache.maven.test.PlexusTestCase; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getTestFile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -61,8 +63,8 @@ import javax.inject.Inject; /** * @author Michal Maczka */ +@PlexusTest public class DefaultWagonManagerTest - extends PlexusTestCase { @Inject private WagonManager wagonManager; diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java index 61f16cceb1..e2c90b10bf 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java @@ -22,7 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.Authentication; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Server; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +37,8 @@ import javax.inject.Inject; * * @author Benjamin Bentmann */ +@PlexusTest public class LegacyRepositorySystemTest - extends PlexusTestCase { @Inject private RepositorySystem repositorySystem; diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java index 0ef67d9be4..a0aa3366d4 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java @@ -49,7 +49,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -65,8 +65,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * * @author Brett Porter */ +@PlexusTest public class DefaultArtifactCollectorTest - extends PlexusTestCase { @Inject private LegacyArtifactCollector artifactCollector; @@ -81,12 +81,9 @@ public class DefaultArtifactCollectorTest private static final String GROUP_ID = "test"; @BeforeEach - @Override public void setUp() throws Exception { - super.setUp(); - source = new Source(); projectArtifact = createArtifactSpec( "project", "1.0", null ); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java index fbb2531a7b..343e943ce6 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java @@ -27,7 +27,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; +import org.codehaus.plexus.PlexusContainer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -41,8 +42,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * * @author Mark Hobson */ +@PlexusTest public abstract class AbstractConflictResolverTest - extends PlexusTestCase { // constants -------------------------------------------------------------- @@ -63,6 +64,9 @@ public abstract class AbstractConflictResolverTest private ConflictResolver conflictResolver; + @Inject + protected PlexusContainer container; + // constructors ----------------------------------------------------------- public AbstractConflictResolverTest( String roleHint ) @@ -77,35 +81,16 @@ public abstract class AbstractConflictResolverTest * @see junit.framework.TestCase#setUp() */ @BeforeEach - @Override public void setUp() throws Exception { - super.setUp(); - - conflictResolver = lookup( ConflictResolver.ROLE, roleHint ); + conflictResolver = (ConflictResolver) container.lookup( ConflictResolver.ROLE, roleHint ); a1 = createArtifact( "a", "1.0" ); a2 = createArtifact( "a", "2.0" ); b1 = createArtifact( "b", "1.0" ); } - /* - * @see org.codehaus.plexus.PlexusTestCase#tearDown() - */ - @AfterEach - @Override - public void tearDown() throws Exception - { - a1 = null; - a2 = null; - b1 = null; - - conflictResolver = null; - - super.tearDown(); - } - // protected methods ------------------------------------------------------ protected ConflictResolver getConflictResolver() diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java index ebe0fd50aa..d5e2389f58 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java @@ -18,7 +18,7 @@ package org.apache.maven.repository.metadata; import javax.inject.Inject; import org.apache.maven.artifact.ArtifactScopeEnum; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; @@ -30,9 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * @author Oleg Gusakov * */ - +@PlexusTest public class DefaultClasspathTransformationTest -extends PlexusTestCase { @Inject ClasspathTransformation transform; @@ -45,11 +44,8 @@ extends PlexusTestCase MetadataGraphVertex v4; //------------------------------------------------------------------------------------------ @BeforeEach - @Override public void setUp() throws Exception { - super.setUp(); - graph = new MetadataGraph( 4, 3 ); /* * v2 diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java index a41464a1c3..9d3e67d1ec 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java @@ -18,7 +18,7 @@ package org.apache.maven.repository.metadata; import javax.inject.Inject; import org.apache.maven.artifact.ArtifactScopeEnum; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,9 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * @author Oleg Gusakov * */ - +@PlexusTest public class DefaultGraphConflictResolverTest -extends PlexusTestCase { @Inject GraphConflictResolver resolver; @@ -45,11 +44,8 @@ extends PlexusTestCase MetadataGraphVertex v4; //------------------------------------------------------------------------------------------ @BeforeEach - @Override public void setUp() throws Exception { - super.setUp(); - /* * v2 * v1< diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 3b5b7a6bd4..14a57680ad 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -44,20 +44,26 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; -import org.junit.jupiter.api.BeforeEach; import javax.inject.Inject; +import static org.apache.maven.test.PlexusExtension.getBasedir; + +@PlexusTest public abstract class AbstractCoreMavenComponentTestCase - extends PlexusTestCase { + + @Inject + protected PlexusContainer container; + @Inject protected RepositorySystem repositorySystem; @@ -66,7 +72,11 @@ public abstract class AbstractCoreMavenComponentTestCase abstract protected String getProjectsDirectory(); - protected File getProject( String name ) + protected PlexusContainer getContainer() { + return container; + } + + protected File getProject(String name ) throws Exception { File source = new File( new File( getBasedir(), getProjectsDirectory() ), name ); @@ -75,20 +85,6 @@ public abstract class AbstractCoreMavenComponentTestCase return new File( target, "pom.xml" ); } - /** - * We need to customize the standard Plexus container with the plugin discovery listener which - * is what looks for the META-INF/maven/plugin.xml resources that enter the system when a Maven - * plugin is loaded. - * - * We also need to customize the Plexus container with a standard plugin discovery listener - * which is the MavenPluginCollector. When a Maven plugin is discovered the MavenPluginCollector - * collects the plugin descriptors which are found. - */ - protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) - { - containerConfiguration.setAutoWiring( true ).setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - } - protected MavenExecutionRequest createMavenExecutionRequest( File pom ) throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java index 3a85ea4ad6..b65d38f472 100644 --- a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java +++ b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java @@ -63,7 +63,7 @@ public class DefaultMavenTest public void testMavenProjectNoDuplicateArtifacts() throws Exception { - MavenProjectHelper mavenProjectHelper = lookup( MavenProjectHelper.class ); + MavenProjectHelper mavenProjectHelper = getContainer().lookup( MavenProjectHelper.class ); MavenProject mavenProject = new MavenProject(); mavenProject.setArtifact( new DefaultArtifact( "g", "a", "1.0", Artifact.SCOPE_TEST, "jar", "", null ) ); File artifactFile = Files.createTempFile( "foo", "tmp").toFile(); diff --git a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java index 13ff67a1d6..6d8f975123 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java +++ b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java @@ -101,12 +101,6 @@ public class MavenLifecycleParticipantTest } } - @Override - protected void setupContainer() - { - super.setupContainer(); - } - @Override protected String getProjectsDirectory() { diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java index 777bae5a8b..2aab3db22f 100644 --- a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java @@ -28,6 +28,7 @@ import org.apache.maven.project.MavenProject; import javax.inject.Inject; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.hamcrest.Matchers.endsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java index 6dba994a39..72719c9974 100644 --- a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java +++ b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java @@ -22,15 +22,23 @@ package org.apache.maven.artifact.handler; import java.io.File; import java.util.List; -import org.apache.maven.test.PlexusTestCase; +import javax.inject.Inject; + +import org.apache.maven.test.PlexusExtension; +import org.apache.maven.test.PlexusTest; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getTestFile; import static org.junit.jupiter.api.Assertions.assertEquals; +@PlexusTest public class ArtifactHandlerTest - extends PlexusTestCase { + @Inject + PlexusContainer container; + @Test public void testAptConsistency() throws Exception @@ -66,7 +74,7 @@ public class ArtifactHandlerTest String addedToClasspath = trimApt( cols[6] ); String includesDependencies = trimApt( cols[7] ); - ArtifactHandler handler = lookup( ArtifactHandler.class, type ); + ArtifactHandler handler = container.lookup( ArtifactHandler.class, type ); assertEquals( handler.getExtension(), extension, type + " extension" ); assertEquals( handler.getPackaging(), packaging, type + " packaging" ); assertEquals( handler.getClassifier(), classifier, type + " classifier" ); diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java index e57e79133f..46191c50e3 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java @@ -8,7 +8,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Repository; import org.apache.maven.settings.Settings; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,9 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * specific language governing permissions and limitations * under the License. */ - +@PlexusTest public class DefaultMavenExecutionRequestPopulatorTest - extends PlexusTestCase { @Inject MavenExecutionRequestPopulator testee; diff --git a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java index d2f29e2dee..4a8f9c0919 100644 --- a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java @@ -37,12 +37,11 @@ import org.apache.maven.project.collector.MultiModuleCollectionStrategy; import org.apache.maven.project.collector.PomlessCollectionStrategy; import org.apache.maven.project.collector.ProjectsSelector; import org.apache.maven.project.collector.RequestPomCollectionStrategy; -import org.apache.maven.test.Parameter; -import org.apache.maven.test.Parameterized; -import org.apache.maven.test.Parameters; -import org.apache.maven.test.Test; import org.codehaus.plexus.util.StringUtils; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.util.ArrayList; @@ -60,11 +59,12 @@ import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_DOWN import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_UPSTREAM; import static org.apache.maven.graph.DefaultGraphBuilderTest.ScenarioBuilder.scenario; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@Parameterized public class DefaultGraphBuilderTest { /* @@ -103,26 +103,9 @@ public class DefaultGraphBuilderTest private Map artifactIdProjectMap; - // Parameters for the test - @Parameter( 0 ) - private String parameterDescription; - @Parameter( 1 ) - private List parameterSelectedProjects; - @Parameter( 2 ) - private List parameterExcludedProjects; - @Parameter( 3 ) - private String parameterResumeFrom; - @Parameter( 4 ) - private String parameterMakeBehavior; - @Parameter( 5 ) - private List parameterExpectedResult; - @Parameter( 6 ) - private File parameterRequestedPom; - - @Parameters(name = "{index}. {0}") - public static Collection parameters() + public static Stream parameters() { - return asList( + return Stream.of( scenario( "Full reactor in order" ) .expectResult( PARENT_MODULE, MODULE_C, MODULE_C_1, MODULE_A, MODULE_B, MODULE_C_2, INDEPENDENT_MODULE ), scenario( "Selected project" ) @@ -198,8 +181,16 @@ public class DefaultGraphBuilderTest ); } - @Test - public void testGetReactorProjects() + @ParameterizedTest + @MethodSource("parameters") + public void testGetReactorProjects( + String parameterDescription, + List parameterSelectedProjects, + List parameterExcludedProjects, + String parameterResumeFrom, + String parameterMakeBehavior, + List parameterExpectedResult, + File parameterRequestedPom) { // Given List selectedProjects = parameterSelectedProjects.stream().map( p -> ":" + p ).collect( Collectors.toList() ); @@ -350,11 +341,11 @@ public class DefaultGraphBuilderTest return this; } - public Object[] expectResult( String... expectedReactorProjects ) + public Arguments expectResult( String... expectedReactorProjects ) { - return new Object[] { + return Arguments.arguments( description, selectedProjects, excludedProjects, resumeFrom, makeBehavior, asList( expectedReactorProjects ), requestedPom - }; + ); } } } \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java index 2378ddd2af..aea902d101 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java @@ -23,7 +23,7 @@ import java.util.stream.Collectors; import javax.inject.Inject; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,9 +35,8 @@ import static org.hamcrest.Matchers.is; /** * @author Kristian Rosenvold */ - +@PlexusTest public class DefaultLifecyclesTest - extends PlexusTestCase { @Inject private DefaultLifecycles defaultLifeCycles; diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index 448ffda3ca..b4c12a3e28 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -500,8 +500,8 @@ public class LifecycleExecutorTest log.add( "afterProjectExecutionFailure " + event.getProject().getArtifactId() ); } }; - lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener ); - lookup( DelegatingMojoExecutionListener.class ).addMojoExecutionListener( mojoListener ); + getContainer().lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener ); + getContainer().lookup( DelegatingMojoExecutionListener.class ).addMojoExecutionListener( mojoListener ); try { @@ -509,8 +509,8 @@ public class LifecycleExecutorTest } finally { - lookup( DelegatingProjectExecutionListener.class ).removeProjectExecutionListener( projectListener ); - lookup( DelegatingMojoExecutionListener.class ).removeMojoExecutionListener( mojoListener ); + getContainer().lookup( DelegatingProjectExecutionListener.class ).removeProjectExecutionListener( projectListener ); + getContainer().lookup( DelegatingMojoExecutionListener.class ).removeMojoExecutionListener( mojoListener ); } List expectedLog = Arrays.asList( "beforeProjectExecution project-basic", // diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 9c0da4fa4f..b0b9b1ff60 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -50,6 +50,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getTestFile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index 8b0cec08fa..d146927069 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -27,7 +27,8 @@ import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; +import org.codehaus.plexus.PlexusContainer; import org.eclipse.aether.DefaultRepositorySystemSession; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -37,28 +38,33 @@ import javax.inject.Inject; /** * @author Jason van Zyl */ +@PlexusTest public abstract class AbstractMavenProjectTestCase - extends PlexusTestCase { protected ProjectBuilder projectBuilder; @Inject protected RepositorySystem repositorySystem; + @Inject + protected PlexusContainer container; + + public PlexusContainer getContainer() { + return container; + } + @BeforeEach public void setUp() throws Exception { - super.setUp(); - if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) { - projectBuilder = lookup( ProjectBuilder.class, "test" ); + projectBuilder = getContainer().lookup( ProjectBuilder.class, "test" ); } else { // default over to the main project builder... - projectBuilder = lookup( ProjectBuilder.class ); + projectBuilder = getContainer().lookup( ProjectBuilder.class ); } } @@ -67,12 +73,6 @@ public abstract class AbstractMavenProjectTestCase return projectBuilder; } - @Override - protected String getCustomConfigurationName() - { - return AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml"; - } - // ---------------------------------------------------------------------- // Local repository // ---------------------------------------------------------------------- diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java index d73b4887db..73942a0e78 100644 --- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getTestFile; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -54,7 +55,7 @@ public class DefaultMavenProjectBuilderTest { super.setUp(); - projectBuilder = lookup( ProjectBuilder.class ); + projectBuilder = getContainer().lookup( ProjectBuilder.class ); localRepoDir = new File( System.getProperty( "java.io.tmpdir" ), "local-repo." + System.currentTimeMillis() ); localRepoDir.mkdirs(); @@ -62,13 +63,10 @@ public class DefaultMavenProjectBuilderTest filesToDelete.add( localRepoDir ); } - @Override @AfterEach public void tearDown() throws Exception { - super.tearDown(); - if ( !filesToDelete.isEmpty() ) { for ( File file : filesToDelete ) diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 6a53907e10..e9492ae52f 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -28,7 +28,7 @@ import java.util.Properties; import javax.inject.Inject; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -43,6 +43,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.lessThan; @@ -54,8 +55,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; +@PlexusTest public class PomConstructionTest - extends PlexusTestCase { private static String BASE_DIR = "src/test"; @@ -75,20 +76,10 @@ public class PomConstructionTest public void setUp() throws Exception { - super.setUp(); testDirectory = new File( getBasedir(), BASE_POM_DIR ); new File( getBasedir(), BASE_MIXIN_DIR ); } - @AfterEach - public void tearDown() - throws Exception - { - projectBuilder = null; - - super.tearDown(); - } - /** * Will throw exception if url is empty. MNG-4050 * diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java index 506a84470b..f23132ce86 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java @@ -85,7 +85,7 @@ public class ProjectBuilderTest configuration.setRepositorySession( mavenSession.getRepositorySession() ); ModelSource modelSource = new FileModelSource( pomFile ); ProjectBuildingResult result = - lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration ); + getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration ); assertNotNull( result.getProject().getParentFile() ); } @@ -100,7 +100,7 @@ public class ProjectBuilderTest configuration.setRepositorySession( mavenSession.getRepositorySession() ); ProjectBuildingException e = assertThrows( ProjectBuildingException.class, - () -> lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ) ); + () -> getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ) ); assertThat( e.getMessage(), containsString( "[ERROR] 'dependencies.dependency.version' for org.apache.maven.its:a:jar is missing. " + "@ line 9, column 17" ) ); @@ -117,11 +117,11 @@ public class ProjectBuilderTest configuration.setResolveDependencies( true ); // single project build entry point - ProjectBuildingResult result = lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ); + ProjectBuildingResult result = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ); assertEquals( 1, result.getProject().getArtifacts().size() ); // multi projects build entry point List results = - lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, + getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, configuration ); assertEquals( 1, results.size() ); MavenProject mavenProject = results.get( 0 ).getProject(); @@ -139,10 +139,10 @@ public class ProjectBuilderTest configuration.setResolveDependencies( false ); // single project build entry point - ProjectBuildingResult result = lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ); + ProjectBuildingResult result = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ); assertEquals( 0, result.getProject().getArtifacts().size() ); // multi projects build entry point - List results = lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, configuration ); + List results = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, configuration ); assertEquals( 1, results.size() ); MavenProject mavenProject = results.get( 0 ).getProject(); assertEquals( 0, mavenProject.getArtifacts().size() ); @@ -161,7 +161,7 @@ public class ProjectBuilderTest MavenSession mavenSession = createMavenSession( null ); ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); configuration.setRepositorySession( mavenSession.getRepositorySession() ); - org.apache.maven.project.ProjectBuilder projectBuilder = lookup( org.apache.maven.project.ProjectBuilder.class ); + org.apache.maven.project.ProjectBuilder projectBuilder = getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ); File child = new File( tempDir.toFile(), "child/pom.xml" ); // build project once projectBuilder.build( child, configuration ); @@ -199,7 +199,7 @@ public class ProjectBuilderTest configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); configuration.setRepositorySession( mavenSession.getRepositorySession() ); org.apache.maven.project.ProjectBuilder projectBuilder = - lookup( org.apache.maven.project.ProjectBuilder.class ); + getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ); // single project build entry point ProjectBuildingException ex1 = @@ -233,7 +233,7 @@ public class ProjectBuilderTest configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); configuration.setRepositorySession( mavenSession.getRepositorySession() ); org.apache.maven.project.ProjectBuilder projectBuilder = - lookup( org.apache.maven.project.ProjectBuilder.class ); + getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ); // single project build entry point Exception ex = assertThrows( Exception.class, () -> projectBuilder.build( pomFile, configuration ) ); @@ -262,7 +262,7 @@ public class ProjectBuilderTest configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); configuration.setRepositorySession( mavenSession.getRepositorySession() ); org.apache.maven.project.ProjectBuilder projectBuilder = - lookup( org.apache.maven.project.ProjectBuilder.class ); + getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ); // read poms separately boolean parentFileWasFoundOnChild = false; diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java index 4c1dcf4427..9a1d9e3c61 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java @@ -35,6 +35,7 @@ import org.eclipse.aether.impl.RemoteRepositoryManager; import org.eclipse.aether.repository.RemoteRepository; import org.junit.jupiter.api.Test; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -208,8 +209,8 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase final DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession(); repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) ); - return new ProjectModelResolver( repoSession, null, lookup( RepositorySystem.class ), - lookup( RemoteRepositoryManager.class ), + return new ProjectModelResolver( repoSession, null, getContainer().lookup( RepositorySystem.class ), + getContainer().lookup( RemoteRepositoryManager.class ), this.getRemoteRepositories(), ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT, null ); diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java index a69af5e4ad..85c69303ec 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java @@ -19,23 +19,25 @@ package org.apache.maven.project.artifact; * under the License. */ -import org.apache.maven.test.PlexusTestCase; +import javax.inject.Inject; + import org.apache.maven.repository.RepositorySystem; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.apache.maven.test.PlexusTest; +import org.codehaus.plexus.PlexusContainer; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import javax.inject.Inject; - -@Disabled +@PlexusTest public class MavenMetadataSourceTest - extends PlexusTestCase { @Inject private RepositorySystem repositorySystem; + @Inject + PlexusContainer container; + @Test + @Disabled public void testShouldNotCarryExclusionsOverFromDependencyToDependency() throws Exception { @@ -58,21 +60,21 @@ public class MavenMetadataSourceTest dep2.setVersion( "1" ); dep2.setType( "jar" ); - List deps = new ArrayList(); + List deps = new ArrayList<>(); deps.add( dep1 ); deps.add( dep2 ); - ArtifactFactory factory = lookup( ArtifactFactory.class ); + ArtifactFactory factory = container.lookup( ArtifactFactory.class ); ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE ); MavenProject project = new MavenProject( new Model() ); - Set result = project.createArtifacts( dependencyFilter ); + Set result = project.createArtifacts( dependencyFilter ); - for ( Iterator it = result.iterator(); it.hasNext(); ) + for (Iterator it = result.iterator(); it.hasNext(); ) { - Artifact artifact = ( Artifact ) it.next(); + Artifact artifact = it.next(); if ( "test-artifact2".equals( artifact.getArtifactId() ) ) { @@ -84,11 +86,12 @@ public class MavenMetadataSourceTest */ } - //TODO restore these if it makes sense - /* + @Test + @Disabled("TODO restore these if it makes sense") public void testShouldUseCompileScopeIfDependencyScopeEmpty() throws Exception { + /* String groupId = "org.apache.maven"; String artifactId = "maven-model"; @@ -111,21 +114,24 @@ public class MavenMetadataSourceTest Map artifactMap = project.getArtifactMap(); assertNotNull( artifactMap, "artifact-map should not be null." ); - assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() ); + assertEquals( 1, artifactMap.size(), "artifact-map should contain 1 element." ); Artifact artifact = (Artifact) artifactMap.get( key ); assertNotNull( artifact, "dependency artifact not found in map." ); - assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() ); + assertEquals( Artifact.SCOPE_COMPILE, artifact.getScope(), "dependency artifact has wrong scope." ); //check for back-propagation of default scope. - assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() ); + assertEquals( Artifact.SCOPE_COMPILE, dep.getScope(), "default scope NOT back-propagated to dependency." ); + */ } @Test + @Disabled public void testShouldUseInjectedTestScopeFromDependencyManagement() throws Exception { + /* String groupId = "org.apache.maven"; String artifactId = "maven-model"; @@ -163,7 +169,7 @@ public class MavenMetadataSourceTest Map artifactMap = project.getArtifactMap(); assertNotNull( artifactMap, "artifact-map should not be null." ); - assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() ); + assertEquals( 1, artifactMap.size(), "artifact-map should contain 1 element." ); Artifact artifact = (Artifact) artifactMap.get( key ); @@ -172,7 +178,7 @@ public class MavenMetadataSourceTest //check for back-propagation of default scope. assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() ); + */ } - */ } diff --git a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java index 46487377c1..e278d8b9a9 100644 --- a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java +++ b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java @@ -20,9 +20,9 @@ package org.apache.maven.rtinfo.internal; */ import org.apache.maven.rtinfo.RuntimeInformation; +import org.apache.maven.test.PlexusTest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusConstants; -import org.apache.maven.test.PlexusTestCase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,21 +33,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.inject.Inject; +@PlexusTest public class DefaultRuntimeInformationTest - extends PlexusTestCase { @Inject RuntimeInformation rtInfo; - @Override - protected void customizeContainerConfiguration( - ContainerConfiguration configuration) - { - super.customizeContainerConfiguration(configuration); - configuration.setAutoWiring(true); - configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); - } - @Test public void testGetMavenVersion() { diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index b9c9734d36..d0524d7428 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -32,7 +32,7 @@ import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.eclipse.aether.DefaultRepositorySystemSession; @@ -43,10 +43,11 @@ import org.junit.jupiter.api.Test; import javax.inject.Inject; +import static org.apache.maven.test.PlexusExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertEquals; +@PlexusTest public class PomConstructionWithSettingsTest - extends PlexusTestCase { private static final String BASE_DIR = "src/test"; @@ -64,7 +65,6 @@ public class PomConstructionWithSettingsTest public void setUp() throws Exception { - super.setUp(); testDirectory = new File( getBasedir(), BASE_POM_DIR ); } diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java index 0301a605eb..026f30bb84 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java @@ -23,9 +23,10 @@ import java.net.MalformedURLException; import javax.inject.Inject; -import org.apache.maven.test.PlexusTestCase; +import org.apache.maven.test.PlexusTest; import org.apache.maven.repository.internal.util.ConsoleRepositoryListener; import org.apache.maven.repository.internal.util.ConsoleTransferListener; +import org.codehaus.plexus.PlexusContainer; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; @@ -34,24 +35,31 @@ import org.eclipse.aether.repository.RemoteRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import static org.apache.maven.test.PlexusExtension.getTestFile; + +@PlexusTest public abstract class AbstractRepositoryTestCase - extends PlexusTestCase { @Inject protected RepositorySystem system; + @Inject + protected PlexusContainer container; + protected RepositorySystemSession session; @BeforeEach - @Override public void setUp() throws Exception { - super.setUp(); session = newMavenRepositorySystemSession( system ); } - public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system ) + protected PlexusContainer getContainer() { + return container; + } + + public static RepositorySystemSession newMavenRepositorySystemSession(RepositorySystem system ) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java index cd45fe36d9..a68a42f0db 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java @@ -42,7 +42,7 @@ public class DefaultArtifactDescriptorReaderTest throws Exception { // prepare - DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) lookup( ArtifactDescriptorReader.class ); + DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) getContainer().lookup( ArtifactDescriptorReader.class ); RepositoryEventDispatcher eventDispatcher = mock( RepositoryEventDispatcher.class ); diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java index ce09b4b325..1a4d444de4 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java @@ -202,8 +202,8 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase private ModelResolver newModelResolver() throws ComponentLookupException, MalformedURLException { return new DefaultModelResolver( this.session, null, this.getClass().getName(), - lookup( ArtifactResolver.class ), lookup( VersionRangeResolver.class ), - lookup( RemoteRepositoryManager.class ), + getContainer().lookup( ArtifactResolver.class ), getContainer().lookup( VersionRangeResolver.class ), + getContainer().lookup( RemoteRepositoryManager.class ), Arrays.asList( newTestRepository() ) ); } diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java deleted file mode 100644 index f5164c5eef..0000000000 --- a/maven-test-support/src/main/java/org/apache/maven/test/Parameter.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.maven.test; - -/* - * 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.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Parameter - */ -@Retention( RetentionPolicy.RUNTIME ) -public @interface Parameter -{ - int value() default 0; -} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java b/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java deleted file mode 100644 index 5741db49db..0000000000 --- a/maven-test-support/src/main/java/org/apache/maven/test/ParameterizedExtension.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.apache.maven.test; - -/* - * 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.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.junit.jupiter.api.extension.Extension; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.TestInstancePostProcessor; -import org.junit.jupiter.api.extension.TestInstantiationException; -import org.junit.jupiter.api.extension.TestTemplateInvocationContext; -import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; -import org.junit.jupiter.params.converter.DefaultArgumentConverter; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.platform.commons.util.CollectionUtils; -import org.junit.platform.commons.util.ReflectionUtils; - -import static org.junit.jupiter.params.provider.Arguments.arguments; -import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated; - -/** - * ParameterizedExtension - */ -public class ParameterizedExtension implements TestTemplateInvocationContextProvider -{ - - @Override - public boolean supportsTestTemplate( ExtensionContext context ) - { - return context.getTestMethod() - .map( m -> isAnnotated( m, Test.class ) ) - .orElse( false ); - } - - @Override - public Stream provideTestTemplateInvocationContexts( - ExtensionContext extensionContext ) - { - Class testClass = extensionContext.getRequiredTestClass(); - try - { - List parameters = getParametersMethods( testClass ); - if ( parameters.size() != 1 ) - { - throw new IllegalStateException( - "Class " + testClass.getName() + " should provide a single method annotated with @" - + Parameters.class.getSimpleName() ); - } - Object params = parameters.iterator().next().invoke( null ); - return CollectionUtils.toStream( params ) - .map( ParameterizedExtension::toArguments ) - .map( Arguments::get ) - .map( ParameterizedTemplate::new ); - } - catch ( Exception e ) - { - throw new IllegalStateException( "Unable to generate test templates for class " + testClass.getName(), e ); - } - } - - private List getParametersMethods( Class testClass ) - { - List parameters = Stream.of( testClass.getDeclaredMethods() ) - .filter( m -> Modifier.isStatic( m.getModifiers() ) ) - .filter( m -> m.getAnnotation( Parameters.class ) != null ) - .collect( Collectors.toList() ); - if ( parameters.isEmpty() && testClass != null ) - { - return getParametersMethods( testClass.getSuperclass() ); - } - else - { - return parameters; - } - } - - private static Arguments toArguments( Object item ) - { - // Nothing to do except cast. - if ( item instanceof Arguments ) - { - return ( Arguments ) item; - } - // Pass all multidimensional arrays "as is", in contrast to Object[]. - // See https://github.com/junit-team/junit5/issues/1665 - if ( ReflectionUtils.isMultidimensionalArray( item ) ) - { - return arguments( item ); - } - // Special treatment for one-dimensional reference arrays. - // See https://github.com/junit-team/junit5/issues/1665 - if ( item instanceof Object[] ) - { - return arguments( ( Object[] ) item ); - } - // Pass everything else "as is". - return arguments( item ); - } - - /** - * ParameterizedTemplate - */ - public static class ParameterizedTemplate implements TestTemplateInvocationContext - { - - private final Object[] params; - - public ParameterizedTemplate( Object[] params ) - { - this.params = params; - } - - @Override - public String getDisplayName( int invocationIndex ) - { - return "[" + invocationIndex + "] " - + Stream.of( params ).map( Object::toString ).collect( Collectors.joining( ", " ) ); - } - - @Override - public List getAdditionalExtensions() - { - return Arrays.asList( - ( TestInstancePostProcessor ) this::postProcessTestInstance ); - } - - protected void postProcessTestInstance( Object testInstance, ExtensionContext context ) throws Exception - { - Class clazz = testInstance.getClass(); - List fields = hierarchy( clazz ) - .map( Class::getDeclaredFields ) - .flatMap( Stream::of ) - .filter( f -> isAnnotated( f, Parameter.class ) ) - .sorted( Comparator.comparing( f -> ( Integer ) f.getAnnotation( Parameter.class ).value() ) ) - .collect( Collectors.toList() ); - if ( params.length != fields.size() ) - { - throw new TestInstantiationException( - "Expected " + fields.size() + " parameters bug got " + params.length + " when instantiating " - + clazz.getName() ); - } - for ( int i = 0; i < fields.size(); i++ ) - { - Field f = fields.get( i ); - f.setAccessible( true ); - f.set( testInstance, DefaultArgumentConverter.INSTANCE.convert( params[i], f.getType() ) ); - } - } - - protected Stream> hierarchy( Class clazz ) - { - Class superclass = clazz.getSuperclass(); - return Stream.concat( Stream.of( clazz ), superclass != null ? hierarchy( superclass ) : Stream.empty() ); - } - - } - -} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java b/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java deleted file mode 100644 index b643a3a98f..0000000000 --- a/maven-test-support/src/main/java/org/apache/maven/test/Parameters.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.test; - -/* - * 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.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Parameters - */ -@Retention( RetentionPolicy.RUNTIME ) -@Target( ElementType.METHOD ) -public @interface Parameters -{ - String name() default "{index}"; -} diff --git a/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java b/maven-test-support/src/main/java/org/apache/maven/test/PlexusExtension.java similarity index 87% rename from maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java rename to maven-test-support/src/main/java/org/apache/maven/test/PlexusExtension.java index 91dc25e15f..c001a6a83c 100644 --- a/maven-test-support/src/main/java/org/apache/maven/test/PlexusTestCase.java +++ b/maven-test-support/src/main/java/org/apache/maven/test/PlexusExtension.java @@ -50,8 +50,9 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.DefaultContext; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; /** * This is a slightly modified version of the original plexus class @@ -64,20 +65,24 @@ import org.junit.jupiter.api.BeforeEach; * @author Michal Maczka * @author Guillaume Nodet */ -public abstract class PlexusTestCase +public class PlexusExtension implements BeforeEachCallback, AfterEachCallback { + private ExtensionContext context; private PlexusContainer container; private static String basedir; - @BeforeEach - public void setUp() + @Override + public void beforeEach( ExtensionContext context ) throws Exception { basedir = getBasedir(); + this.context = context; + + getContainer().addComponent( getContainer(), PlexusContainer.class.getName() ); ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> binder.requestInjection( this ) ); + binder -> binder.requestInjection( context.getRequiredTestInstance() ) ); } @SuppressWarnings( "ResultOfMethodCallIgnored" ) @@ -161,8 +166,8 @@ public abstract class PlexusTestCase return null; } - @AfterEach - public void tearDown() + @Override + public void afterEach( ExtensionContext context ) throws Exception { if ( container != null ) @@ -173,7 +178,7 @@ public abstract class PlexusTestCase } } - protected PlexusContainer getContainer() + public PlexusContainer getContainer() { if ( container == null ) { @@ -211,17 +216,28 @@ public abstract class PlexusTestCase */ protected String getConfigurationName( String subname ) { - return getClass().getName().replace( '.', '/' ) + ".xml"; + Class testClass = context.getRequiredTestClass(); + for ( Class clazz = testClass; + clazz != null; + clazz = clazz.getSuperclass() ) + { + String name = clazz.getName().replace( '.', '/' ) + ".xml"; + if ( testClass.getClassLoader().getResource( name ) != null ) + { + return name; + } + } + return null; } protected InputStream getResourceAsStream( String resource ) { - return getClass().getResourceAsStream( resource ); + return context.getRequiredTestClass().getResourceAsStream( resource ); } protected ClassLoader getClassLoader() { - return getClass().getClassLoader(); + return context.getRequiredTestClass().getClassLoader(); } // ---------------------------------------------------------------------- @@ -313,7 +329,7 @@ public abstract class PlexusTestCase public String getTestConfiguration() { - return getTestConfiguration( getClass() ); + return getTestConfiguration( context.getRequiredTestClass() ); } public static String getTestConfiguration( Class clazz ) diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java similarity index 87% rename from maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java rename to maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java index a15fbaf1f6..e46228bd47 100644 --- a/maven-test-support/src/main/java/org/apache/maven/test/Parameterized.java +++ b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java @@ -27,11 +27,12 @@ import java.lang.annotation.Target; import org.junit.jupiter.api.extension.ExtendWith; /** - * Parameterized + * Plexus test */ -@Target( { ElementType.ANNOTATION_TYPE, ElementType.TYPE } ) @Retention( RetentionPolicy.RUNTIME ) -@ExtendWith( ParameterizedExtension.class ) -public @interface Parameterized +@ExtendWith( PlexusExtension.class ) +@Target( ElementType.TYPE ) +public @interface PlexusTest { + } diff --git a/maven-test-support/src/main/java/org/apache/maven/test/Test.java b/maven-test-support/src/main/java/org/apache/maven/test/Test.java deleted file mode 100644 index 5b542b6638..0000000000 --- a/maven-test-support/src/main/java/org/apache/maven/test/Test.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.test; - -/* - * 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.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import org.junit.jupiter.api.TestTemplate; - -/** - * Test - */ -@Retention( RetentionPolicy.RUNTIME ) -@TestTemplate -public @interface Test -{ -} diff --git a/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java b/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java index dad847e129..fba35218d8 100644 --- a/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java +++ b/maven-xml/src/test/java/org/apache/maven/xml/sax/ext/CommentRenormalizerTest.java @@ -22,34 +22,18 @@ package org.apache.maven.xml.sax.ext; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import java.util.Arrays; -import java.util.Collection; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import org.apache.maven.test.Parameter; -import org.apache.maven.test.Parameterized; -import org.apache.maven.test.Parameters; -import org.apache.maven.test.Test; import org.xml.sax.ext.LexicalHandler; -@Parameterized public class CommentRenormalizerTest { private LexicalHandler lexicalHandler = mock( LexicalHandler.class ); - @Parameter - private String lineSeparator; - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][] { - { "\n" }, - { "\r\n" }, - { "\r" } - }); - } - - @Test - public void singleLine() + @ParameterizedTest + @ValueSource(strings = {"\n", "\r\n", "\r" }) + public void singleLine(String lineSeparator) throws Exception { CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator ); @@ -61,8 +45,9 @@ public class CommentRenormalizerTest verify( lexicalHandler ).comment( ch, 0, ch.length ); } - @Test - public void multiLine() + @ParameterizedTest + @ValueSource(strings = {"\n", "\r\n", "\r" }) + public void multiLine(String lineSeparator) throws Exception { CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator );