This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MNG-7063 in repository https://gitbox.apache.org/repos/asf/maven.git
commit 9905ee36e3c61de1a9fcaa7c82143727aaac6c23 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Mon Jan 18 15:24:31 2021 +0100 Use JUnit 5 extension --- .../AbstractArtifactComponentTestCase.java | 17 ++++++--- .../artifact/deployer/ArtifactDeployerTest.java | 1 + .../factory/DefaultArtifactFactoryTest.java | 4 +- .../artifact/installer/ArtifactInstallerTest.java | 2 + .../artifact/resolver/ArtifactResolverTest.java | 10 ----- .../resolver/DefaultArtifactResolverTest.java | 11 +----- .../transform/TransformationManagerTest.java | 4 +- .../manager/DefaultProfileManagerTest.java | 22 +++++++++-- .../project/AbstractMavenProjectTestCase.java | 38 +++++++------------ .../apache/maven/project/ProjectClasspathTest.java | 12 ++---- .../AbstractProjectInheritanceTestCase.java | 2 + .../repository/LegacyRepositorySystemTest.java | 12 ++++-- .../maven/repository/MirrorProcessorTest.java | 4 +- .../repository/legacy/DefaultWagonManagerTest.java | 6 ++- .../legacy/LegacyRepositorySystemTest.java | 4 +- .../resolver/DefaultArtifactCollectorTest.java | 7 +--- .../conflict/AbstractConflictResolverTest.java | 29 ++++---------- .../DefaultClasspathTransformationTest.java | 8 +--- .../metadata/DefaultGraphConflictResolverTest.java | 8 +--- .../maven/AbstractCoreMavenComponentTestCase.java | 32 +++++++--------- .../java/org/apache/maven/DefaultMavenTest.java | 2 +- .../maven/MavenLifecycleParticipantTest.java | 6 --- .../maven/ProjectDependenciesResolverTest.java | 1 + .../artifact/handler/ArtifactHandlerTest.java | 14 +++++-- .../DefaultMavenExecutionRequestPopulatorTest.java | 5 +-- .../maven/lifecycle/DefaultLifecyclesTest.java | 5 +-- .../maven/lifecycle/LifecycleExecutorTest.java | 8 ++-- .../PluginParameterExpressionEvaluatorTest.java | 1 + .../project/AbstractMavenProjectTestCase.java | 24 ++++++------ .../project/DefaultMavenProjectBuilderTest.java | 6 +-- .../apache/maven/project/PomConstructionTest.java | 15 ++------ .../apache/maven/project/ProjectBuilderTest.java | 20 +++++----- .../maven/project/ProjectModelResolverTest.java | 5 ++- .../project/artifact/MavenMetadataSourceTest.java | 44 ++++++++++++---------- .../internal/DefaultRuntimeInformationTest.java | 13 +------ .../settings/PomConstructionWithSettingsTest.java | 6 +-- .../internal/AbstractRepositoryTestCase.java | 18 ++++++--- .../DefaultArtifactDescriptorReaderTest.java | 2 +- .../internal/DefaultModelResolverTest.java | 4 +- .../{PlexusTestCase.java => PlexusExtension.java} | 42 ++++++++++++++------- .../java/org/apache/maven/test/PlexusTest.java | 38 +++++++++++++++++++ 41 files changed, 264 insertions(+), 248 deletions(-) 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 146ec68..0c6c062 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 <a href="mailto:ja...@maven.org">Jason van Zyl </a> */ -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 05191ae..e321e45 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 6dcf99a..517bc71 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 695c5cc..0010d4f 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 <a href="mailto:ja...@maven.org">Jason van Zyl</a> */ 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 d621d90..6aa0652 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 fdd5f62..23e93be 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 5c1ae2d..08e1055 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 442493a..5c9dc6b 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 338cffa..52f8dfe 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 0cc449f..a2119ce 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 93358ec..2538abc 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 eb56bc8..8505783 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<ArtifactRepository> 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 443bc44..49277ba 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 e6177c7..eefe1b5 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 <a href="michal.mac...@dimatics.com">Michal Maczka</a> */ +@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 61f16cc..e2c90b1 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 0ef67d9..a0aa336 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 <a href="mailto:br...@apache.org">Brett Porter</a> */ +@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 fbb2531..343e943 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 <a href="mailto:markhob...@gmail.com">Mark Hobson</a> */ +@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 ebe0fd5..d5e2389 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 <a href="mailto:o...@codehaus.org">Oleg Gusakov</a> * */ - +@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 a41464a..9d3e67d 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 <a href="mailto:o...@codehaus.org">Oleg Gusakov</a> * */ - +@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 3b5b7a6..14a5768 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 3a85ea4..b65d38f 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 13ff67a..6d8f975 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java +++ b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java @@ -102,12 +102,6 @@ public class MavenLifecycleParticipantTest } @Override - protected void setupContainer() - { - super.setupContainer(); - } - - @Override protected String getProjectsDirectory() { return "src/test/projects/lifecycle-listener"; 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 777bae5..2aab3db 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 6dba994..72719c9 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 e57e791..46191c5 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/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java index 2378ddd..aea902d 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 448ffda..b4c12a3 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<String> 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 9c0da4f..b0b9b1f 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 8b0cec0..d146927 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 d73b488..73942a0 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 6a53907..e9492ae 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 506a844..f23132c 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<ProjectBuildingResult> 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<ProjectBuildingResult> results = lookup( org.apache.maven.project.ProjectBuilder.class ).build( Collections.singletonList( pomFile ), false, configuration ); + List<ProjectBuildingResult> 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 4c1dcf4..9a1d9e3 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 a69af5e..85c6930 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<Dependency> 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<Artifact> result = project.createArtifacts( dependencyFilter ); - for ( Iterator it = result.iterator(); it.hasNext(); ) + for (Iterator<Artifact> 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 4648737..e278d8b 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 b9c9734..d0524d7 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 0301a60..026f30b 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 cd45fe3..a68a42f 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 ce09b4b..1a4d444 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/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 91dc25e..c001a6a 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 <a href="mailto:mic...@codehaus.org">Michal Maczka</a> * @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/PlexusTest.java b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java new file mode 100644 index 0000000..e46228b --- /dev/null +++ b/maven-test-support/src/main/java/org/apache/maven/test/PlexusTest.java @@ -0,0 +1,38 @@ +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; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Plexus test + */ +@Retention( RetentionPolicy.RUNTIME ) +@ExtendWith( PlexusExtension.class ) +@Target( ElementType.TYPE ) +public @interface PlexusTest +{ + +}