[MNG-7077] Use JUnit 5 extension

Signed-off-by: rfscholte <rfscholte@apache.org>
This commit is contained in:
Guillaume Nodet 2021-02-12 17:21:59 +01:00 committed by rfscholte
parent ab20190a1a
commit 48fc10889e
47 changed files with 260 additions and 588 deletions

View File

@ -32,7 +32,7 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; 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.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; 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.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport; import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.collection.DependencyGraphTransformer; 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.AfterEach;
import org.junit.jupiter.api.BeforeEach; 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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
*/ */
public abstract class AbstractArtifactComponentTestCase @PlexusTest
extends PlexusTestCase public abstract class AbstractArtifactComponentTestCase //extends PlexusTestCase
{ {
@Inject @Inject
protected ArtifactFactory artifactFactory; protected ArtifactFactory artifactFactory;
@ -88,12 +90,17 @@ public abstract class AbstractArtifactComponentTestCase
@Inject @Named( "default" ) @Inject @Named( "default" )
ArtifactRepositoryLayout repoLayout; ArtifactRepositoryLayout repoLayout;
@Inject
PlexusContainer container;
public PlexusContainer getContainer() {
return container;
}
@BeforeEach @BeforeEach
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
RepositorySystemSession repoSession = initRepoSession(); RepositorySystemSession repoSession = initRepoSession();
MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(), MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(),
new DefaultMavenExecutionResult() ); new DefaultMavenExecutionResult() );

View File

@ -28,6 +28,7 @@ import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;

View File

@ -21,15 +21,15 @@ package org.apache.maven.artifact.factory;
import javax.inject.Inject; 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.Artifact;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@PlexusTest
public class DefaultArtifactFactoryTest public class DefaultArtifactFactoryTest
extends PlexusTestCase
{ {
@Inject @Inject

View File

@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test;
import javax.inject.Inject; import javax.inject.Inject;
import static org.apache.maven.test.PlexusExtension.getBasedir;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/ */

View File

@ -34,7 +34,6 @@ import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -71,15 +70,6 @@ public class ArtifactResolverTest
projectArtifact = createLocalArtifact( "project", "3.0" ); projectArtifact = createLocalArtifact( "project", "3.0" );
} }
@AfterEach
@Override
public void tearDown()
throws Exception
{
projectArtifact = null;
super.tearDown();
}
@Override @Override
protected String component() protected String component()
{ {

View File

@ -49,15 +49,6 @@ public class DefaultArtifactResolverTest
projectArtifact = createLocalArtifact( "project", "3.0" ); projectArtifact = createLocalArtifact( "project", "3.0" );
} }
@AfterEach
@Override
public void tearDown()
throws Exception
{
projectArtifact = null;
super.tearDown();
}
@Override @Override
protected String component() protected String component()
{ {
@ -114,6 +105,6 @@ public class DefaultArtifactResolverTest
public void testLookup() public void testLookup()
throws Exception throws Exception
{ {
ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" ); ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "default" );
} }
} }

View File

@ -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.LatestArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation; 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 org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -31,8 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject; import javax.inject.Inject;
/** @author Jason van Zyl */ /** @author Jason van Zyl */
@PlexusTest
public class TransformationManagerTest public class TransformationManagerTest
extends PlexusTestCase
{ {
@Inject @Inject
ArtifactTransformationManager tm; ArtifactTransformationManager tm;

View File

@ -22,21 +22,32 @@ package org.apache.maven.profiles.manager;
import java.util.List; import java.util.List;
import java.util.Properties; 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.Activation;
import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.ProfileManager;
import org.codehaus.plexus.PlexusContainer;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@PlexusTest
public class DefaultProfileManagerTest public class DefaultProfileManagerTest
extends PlexusTestCase
{ {
@Inject
PlexusContainer container;
protected PlexusContainer getContainer() {
return container;
}
@Test @Test
public void testShouldActivateDefaultProfile() public void testShouldActivateDefaultProfile()
throws Exception throws Exception
@ -201,10 +212,13 @@ public class DefaultProfileManagerTest
assertNotNull( active ); assertNotNull( active );
assertEquals( 0, active.size() ); assertEquals( 0, active.size() );
} }
/*
@Test
@Disabled
public void testOsActivationProfile() public void testOsActivationProfile()
throws Exception throws Exception
{ {
/*
Profile osActivated = new Profile(); Profile osActivated = new Profile();
osActivated.setId( "os-profile" ); osActivated.setId( "os-profile" );
@ -229,7 +243,7 @@ public class DefaultProfileManagerTest
assertNotNull( active ); assertNotNull( active );
assertEquals( 1, active.size() ); assertEquals( 1, active.size() );
*/
} }
*/
} }

View File

@ -24,13 +24,14 @@ import java.util.Arrays;
import javax.inject.Inject; 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.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -40,54 +41,41 @@ import static org.junit.jupiter.api.Assertions.fail;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
*/ */
@PlexusTest
public abstract class AbstractMavenProjectTestCase public abstract class AbstractMavenProjectTestCase
extends PlexusTestCase
{ {
protected ProjectBuilder projectBuilder; protected ProjectBuilder projectBuilder;
@Inject @Inject
protected RepositorySystem repositorySystem; protected RepositorySystem repositorySystem;
@Override @Inject
protected PlexusContainer container;
public PlexusContainer getContainer() {
return container;
}
@BeforeEach @BeforeEach
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
{ {
projectBuilder = lookup( ProjectBuilder.class, "test" ); projectBuilder = getContainer().lookup( ProjectBuilder.class, "test" );
} }
else else
{ {
// default over to the main project builder... // 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() protected ProjectBuilder getProjectBuilder()
{ {
return projectBuilder; return projectBuilder;
} }
@Override
protected String getCustomConfigurationName()
{
String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
System.out.println( name );
return name;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Local repository // Local repository
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -118,7 +106,7 @@ public abstract class AbstractMavenProjectTestCase
protected ArtifactRepository getLocalRepository() protected ArtifactRepository getLocalRepository()
throws Exception throws Exception
{ {
ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class ); ArtifactRepositoryLayout repoLayout = getContainer().lookup( ArtifactRepositoryLayout.class );
ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null ); ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null );

View File

@ -44,17 +44,11 @@ public class ProjectClasspathTest
{ {
super.setUp(); super.setUp();
ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" ); ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "classpath" );
DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class); DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)getContainer().lookup(ArtifactDescriptorReader.class);
pomReader.setArtifactResolver( resolver ); pomReader.setArtifactResolver( resolver );
projectBuilder = lookup( ProjectBuilder.class, "classpath" ); projectBuilder = getContainer().lookup( ProjectBuilder.class, "classpath" );
}
@Override
protected String getCustomConfigurationName()
{
return null;
} }
@Test @Test

View File

@ -23,6 +23,8 @@ import java.io.File;
import org.apache.maven.project.AbstractMavenProjectTestCase; import org.apache.maven.project.AbstractMavenProjectTestCase;
import static org.apache.maven.test.PlexusExtension.getTestFile;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
*/ */

View File

@ -32,7 +32,8 @@ import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.plugin.LegacySupport; import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.legacy.LegacyRepositorySystem; 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.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; 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.BeforeEach;
import org.junit.jupiter.api.Test; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -51,13 +53,15 @@ import javax.inject.Inject;
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
@PlexusTest
public class LegacyRepositorySystemTest public class LegacyRepositorySystemTest
extends PlexusTestCase
{ {
@Inject @Inject
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Inject @Inject
private ResolutionErrorHandler resolutionErrorHandler; private ResolutionErrorHandler resolutionErrorHandler;
@Inject
private PlexusContainer container;
protected List<ArtifactRepository> getRemoteRepositories() protected List<ArtifactRepository> getRemoteRepositories()
throws Exception throws Exception
@ -110,8 +114,8 @@ public class LegacyRepositorySystemTest
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(); DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() ); LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() );
session.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( session, localRepo ) ); session.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( session, localRepo ) );
LegacySupport legacySupport = lookup( LegacySupport.class ); LegacySupport legacySupport = container.lookup( LegacySupport.class );
legacySupport.setSession( new MavenSession( getContainer(), session, new DefaultMavenExecutionRequest(), legacySupport.setSession( new MavenSession( container, session, new DefaultMavenExecutionRequest(),
new DefaultMavenExecutionResult() ) ); new DefaultMavenExecutionResult() ) );
ArtifactResolutionResult result = repositorySystem.resolve( request ); ArtifactResolutionResult result = repositorySystem.resolve( request );

View File

@ -22,7 +22,7 @@ package org.apache.maven.repository;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
@ -38,8 +38,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject; import javax.inject.Inject;
@PlexusTest
public class MirrorProcessorTest public class MirrorProcessorTest
extends PlexusTestCase
{ {
@Inject @Inject
private DefaultMirrorSelector mirrorSelector; private DefaultMirrorSelector mirrorSelector;

View File

@ -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.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; 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.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException; 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.events.TransferListener;
import org.apache.maven.wagon.observers.AbstractTransferListener; import org.apache.maven.wagon.observers.AbstractTransferListener;
import org.apache.maven.wagon.observers.Debug; 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.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -61,8 +63,8 @@ import javax.inject.Inject;
/** /**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
*/ */
@PlexusTest
public class DefaultWagonManagerTest public class DefaultWagonManagerTest
extends PlexusTestCase
{ {
@Inject @Inject
private WagonManager wagonManager; private WagonManager wagonManager;

View File

@ -22,7 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.Authentication; import org.apache.maven.artifact.repository.Authentication;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Server; 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.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -37,8 +37,8 @@ import javax.inject.Inject;
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
@PlexusTest
public class LegacyRepositorySystemTest public class LegacyRepositorySystemTest
extends PlexusTestCase
{ {
@Inject @Inject
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;

View File

@ -49,7 +49,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; 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.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
@ -65,8 +65,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* *
* @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/ */
@PlexusTest
public class DefaultArtifactCollectorTest public class DefaultArtifactCollectorTest
extends PlexusTestCase
{ {
@Inject @Inject
private LegacyArtifactCollector artifactCollector; private LegacyArtifactCollector artifactCollector;
@ -81,12 +81,9 @@ public class DefaultArtifactCollectorTest
private static final String GROUP_ID = "test"; private static final String GROUP_ID = "test";
@BeforeEach @BeforeEach
@Override
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
source = new Source(); source = new Source();
projectArtifact = createArtifactSpec( "project", "1.0", null ); projectArtifact = createArtifactSpec( "project", "1.0", null );

View File

@ -27,7 +27,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.resolver.ResolutionNode;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange; 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.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -41,8 +42,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* *
* @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a> * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
*/ */
@PlexusTest
public abstract class AbstractConflictResolverTest public abstract class AbstractConflictResolverTest
extends PlexusTestCase
{ {
// constants -------------------------------------------------------------- // constants --------------------------------------------------------------
@ -63,6 +64,9 @@ public abstract class AbstractConflictResolverTest
private ConflictResolver conflictResolver; private ConflictResolver conflictResolver;
@Inject
protected PlexusContainer container;
// constructors ----------------------------------------------------------- // constructors -----------------------------------------------------------
public AbstractConflictResolverTest( String roleHint ) public AbstractConflictResolverTest( String roleHint )
@ -77,35 +81,16 @@ public abstract class AbstractConflictResolverTest
* @see junit.framework.TestCase#setUp() * @see junit.framework.TestCase#setUp()
*/ */
@BeforeEach @BeforeEach
@Override
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp(); conflictResolver = (ConflictResolver) container.lookup( ConflictResolver.ROLE, roleHint );
conflictResolver = lookup( ConflictResolver.ROLE, roleHint );
a1 = createArtifact( "a", "1.0" ); a1 = createArtifact( "a", "1.0" );
a2 = createArtifact( "a", "2.0" ); a2 = createArtifact( "a", "2.0" );
b1 = createArtifact( "b", "1.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 methods ------------------------------------------------------
protected ConflictResolver getConflictResolver() protected ConflictResolver getConflictResolver()

View File

@ -18,7 +18,7 @@ package org.apache.maven.repository.metadata;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.maven.artifact.ArtifactScopeEnum; 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.Test;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -30,9 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
* *
*/ */
@PlexusTest
public class DefaultClasspathTransformationTest public class DefaultClasspathTransformationTest
extends PlexusTestCase
{ {
@Inject @Inject
ClasspathTransformation transform; ClasspathTransformation transform;
@ -45,11 +44,8 @@ extends PlexusTestCase
MetadataGraphVertex v4; MetadataGraphVertex v4;
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
@BeforeEach @BeforeEach
@Override
public void setUp() throws Exception public void setUp() throws Exception
{ {
super.setUp();
graph = new MetadataGraph( 4, 3 ); graph = new MetadataGraph( 4, 3 );
/* /*
* v2 * v2

View File

@ -18,7 +18,7 @@ package org.apache.maven.repository.metadata;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.maven.artifact.ArtifactScopeEnum; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -30,9 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
* *
*/ */
@PlexusTest
public class DefaultGraphConflictResolverTest public class DefaultGraphConflictResolverTest
extends PlexusTestCase
{ {
@Inject @Inject
GraphConflictResolver resolver; GraphConflictResolver resolver;
@ -45,11 +44,8 @@ extends PlexusTestCase
MetadataGraphVertex v4; MetadataGraphVertex v4;
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
@BeforeEach @BeforeEach
@Override
public void setUp() throws Exception public void setUp() throws Exception
{ {
super.setUp();
/* /*
* v2 * v2
* v1< * v1<

View File

@ -44,20 +44,26 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; 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.ContainerConfiguration;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepository;
import org.junit.jupiter.api.BeforeEach;
import javax.inject.Inject; import javax.inject.Inject;
import static org.apache.maven.test.PlexusExtension.getBasedir;
@PlexusTest
public abstract class AbstractCoreMavenComponentTestCase public abstract class AbstractCoreMavenComponentTestCase
extends PlexusTestCase
{ {
@Inject
protected PlexusContainer container;
@Inject @Inject
protected RepositorySystem repositorySystem; protected RepositorySystem repositorySystem;
@ -66,7 +72,11 @@ public abstract class AbstractCoreMavenComponentTestCase
abstract protected String getProjectsDirectory(); abstract protected String getProjectsDirectory();
protected File getProject( String name ) protected PlexusContainer getContainer() {
return container;
}
protected File getProject(String name )
throws Exception throws Exception
{ {
File source = new File( new File( getBasedir(), getProjectsDirectory() ), name ); File source = new File( new File( getBasedir(), getProjectsDirectory() ), name );
@ -75,20 +85,6 @@ public abstract class AbstractCoreMavenComponentTestCase
return new File( target, "pom.xml" ); 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 ) protected MavenExecutionRequest createMavenExecutionRequest( File pom )
throws Exception throws Exception
{ {

View File

@ -63,7 +63,7 @@ public class DefaultMavenTest
public void testMavenProjectNoDuplicateArtifacts() public void testMavenProjectNoDuplicateArtifacts()
throws Exception throws Exception
{ {
MavenProjectHelper mavenProjectHelper = lookup( MavenProjectHelper.class ); MavenProjectHelper mavenProjectHelper = getContainer().lookup( MavenProjectHelper.class );
MavenProject mavenProject = new MavenProject(); MavenProject mavenProject = new MavenProject();
mavenProject.setArtifact( new DefaultArtifact( "g", "a", "1.0", Artifact.SCOPE_TEST, "jar", "", null ) ); mavenProject.setArtifact( new DefaultArtifact( "g", "a", "1.0", Artifact.SCOPE_TEST, "jar", "", null ) );
File artifactFile = Files.createTempFile( "foo", "tmp").toFile(); File artifactFile = Files.createTempFile( "foo", "tmp").toFile();

View File

@ -101,12 +101,6 @@ public class MavenLifecycleParticipantTest
} }
} }
@Override
protected void setupContainer()
{
super.setupContainer();
}
@Override @Override
protected String getProjectsDirectory() protected String getProjectsDirectory()
{ {

View File

@ -28,6 +28,7 @@ import org.apache.maven.project.MavenProject;
import javax.inject.Inject; import javax.inject.Inject;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.apache.maven.test.PlexusExtension.getBasedir;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;

View File

@ -22,15 +22,23 @@ package org.apache.maven.artifact.handler;
import java.io.File; import java.io.File;
import java.util.List; 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.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test; 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.assertEquals;
@PlexusTest
public class ArtifactHandlerTest public class ArtifactHandlerTest
extends PlexusTestCase
{ {
@Inject
PlexusContainer container;
@Test @Test
public void testAptConsistency() public void testAptConsistency()
throws Exception throws Exception
@ -66,7 +74,7 @@ public class ArtifactHandlerTest
String addedToClasspath = trimApt( cols[6] ); String addedToClasspath = trimApt( cols[6] );
String includesDependencies = trimApt( cols[7] ); 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.getExtension(), extension, type + " extension" );
assertEquals( handler.getPackaging(), packaging, type + " packaging" ); assertEquals( handler.getPackaging(), packaging, type + " packaging" );
assertEquals( handler.getClassifier(), classifier, type + " classifier" ); assertEquals( handler.getClassifier(), classifier, type + " classifier" );

View File

@ -8,7 +8,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.settings.Profile; import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Repository; import org.apache.maven.settings.Repository;
import org.apache.maven.settings.Settings; 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 org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; 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 * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
@PlexusTest
public class DefaultMavenExecutionRequestPopulatorTest public class DefaultMavenExecutionRequestPopulatorTest
extends PlexusTestCase
{ {
@Inject @Inject
MavenExecutionRequestPopulator testee; MavenExecutionRequestPopulator testee;

View File

@ -37,12 +37,11 @@ import org.apache.maven.project.collector.MultiModuleCollectionStrategy;
import org.apache.maven.project.collector.PomlessCollectionStrategy; import org.apache.maven.project.collector.PomlessCollectionStrategy;
import org.apache.maven.project.collector.ProjectsSelector; import org.apache.maven.project.collector.ProjectsSelector;
import org.apache.maven.project.collector.RequestPomCollectionStrategy; 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.codehaus.plexus.util.StringUtils;
import org.junit.jupiter.api.BeforeEach; 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.io.File;
import java.util.ArrayList; 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.execution.MavenExecutionRequest.REACTOR_MAKE_UPSTREAM;
import static org.apache.maven.graph.DefaultGraphBuilderTest.ScenarioBuilder.scenario; import static org.apache.maven.graph.DefaultGraphBuilderTest.ScenarioBuilder.scenario;
import static org.junit.jupiter.api.Assertions.assertEquals; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@Parameterized
public class DefaultGraphBuilderTest public class DefaultGraphBuilderTest
{ {
/* /*
@ -103,26 +103,9 @@ public class DefaultGraphBuilderTest
private Map<String, MavenProject> artifactIdProjectMap; private Map<String, MavenProject> artifactIdProjectMap;
// Parameters for the test public static Stream<Arguments> parameters()
@Parameter( 0 )
private String parameterDescription;
@Parameter( 1 )
private List<String> parameterSelectedProjects;
@Parameter( 2 )
private List<String> parameterExcludedProjects;
@Parameter( 3 )
private String parameterResumeFrom;
@Parameter( 4 )
private String parameterMakeBehavior;
@Parameter( 5 )
private List<String> parameterExpectedResult;
@Parameter( 6 )
private File parameterRequestedPom;
@Parameters(name = "{index}. {0}")
public static Collection<Object[]> parameters()
{ {
return asList( return Stream.of(
scenario( "Full reactor in order" ) scenario( "Full reactor in order" )
.expectResult( PARENT_MODULE, MODULE_C, MODULE_C_1, MODULE_A, MODULE_B, MODULE_C_2, INDEPENDENT_MODULE ), .expectResult( PARENT_MODULE, MODULE_C, MODULE_C_1, MODULE_A, MODULE_B, MODULE_C_2, INDEPENDENT_MODULE ),
scenario( "Selected project" ) scenario( "Selected project" )
@ -198,8 +181,16 @@ public class DefaultGraphBuilderTest
); );
} }
@Test @ParameterizedTest
public void testGetReactorProjects() @MethodSource("parameters")
public void testGetReactorProjects(
String parameterDescription,
List<String> parameterSelectedProjects,
List<String> parameterExcludedProjects,
String parameterResumeFrom,
String parameterMakeBehavior,
List<String> parameterExpectedResult,
File parameterRequestedPom)
{ {
// Given // Given
List<String> selectedProjects = parameterSelectedProjects.stream().map( p -> ":" + p ).collect( Collectors.toList() ); List<String> selectedProjects = parameterSelectedProjects.stream().map( p -> ":" + p ).collect( Collectors.toList() );
@ -350,11 +341,11 @@ public class DefaultGraphBuilderTest
return this; 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 description, selectedProjects, excludedProjects, resumeFrom, makeBehavior, asList( expectedReactorProjects ), requestedPom
}; );
} }
} }
} }

View File

@ -23,7 +23,7 @@ import java.util.stream.Collectors;
import javax.inject.Inject; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -35,9 +35,8 @@ import static org.hamcrest.Matchers.is;
/** /**
* @author Kristian Rosenvold * @author Kristian Rosenvold
*/ */
@PlexusTest
public class DefaultLifecyclesTest public class DefaultLifecyclesTest
extends PlexusTestCase
{ {
@Inject @Inject
private DefaultLifecycles defaultLifeCycles; private DefaultLifecycles defaultLifeCycles;

View File

@ -500,8 +500,8 @@ public class LifecycleExecutorTest
log.add( "afterProjectExecutionFailure " + event.getProject().getArtifactId() ); log.add( "afterProjectExecutionFailure " + event.getProject().getArtifactId() );
} }
}; };
lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener ); getContainer().lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener );
lookup( DelegatingMojoExecutionListener.class ).addMojoExecutionListener( mojoListener ); getContainer().lookup( DelegatingMojoExecutionListener.class ).addMojoExecutionListener( mojoListener );
try try
{ {
@ -509,8 +509,8 @@ public class LifecycleExecutorTest
} }
finally finally
{ {
lookup( DelegatingProjectExecutionListener.class ).removeProjectExecutionListener( projectListener ); getContainer().lookup( DelegatingProjectExecutionListener.class ).removeProjectExecutionListener( projectListener );
lookup( DelegatingMojoExecutionListener.class ).removeMojoExecutionListener( mojoListener ); getContainer().lookup( DelegatingMojoExecutionListener.class ).removeMojoExecutionListener( mojoListener );
} }
List<String> expectedLog = Arrays.asList( "beforeProjectExecution project-basic", // List<String> expectedLog = Arrays.asList( "beforeProjectExecution project-basic", //

View File

@ -50,6 +50,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;

View File

@ -27,7 +27,8 @@ import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; 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.eclipse.aether.DefaultRepositorySystemSession;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -37,28 +38,33 @@ import javax.inject.Inject;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
*/ */
@PlexusTest
public abstract class AbstractMavenProjectTestCase public abstract class AbstractMavenProjectTestCase
extends PlexusTestCase
{ {
protected ProjectBuilder projectBuilder; protected ProjectBuilder projectBuilder;
@Inject @Inject
protected RepositorySystem repositorySystem; protected RepositorySystem repositorySystem;
@Inject
protected PlexusContainer container;
public PlexusContainer getContainer() {
return container;
}
@BeforeEach @BeforeEach
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
{ {
projectBuilder = lookup( ProjectBuilder.class, "test" ); projectBuilder = getContainer().lookup( ProjectBuilder.class, "test" );
} }
else else
{ {
// default over to the main project builder... // 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; return projectBuilder;
} }
@Override
protected String getCustomConfigurationName()
{
return AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Local repository // Local repository
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View File

@ -30,6 +30,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.apache.maven.test.PlexusExtension.getTestFile;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -54,7 +55,7 @@ public class DefaultMavenProjectBuilderTest
{ {
super.setUp(); super.setUp();
projectBuilder = lookup( ProjectBuilder.class ); projectBuilder = getContainer().lookup( ProjectBuilder.class );
localRepoDir = new File( System.getProperty( "java.io.tmpdir" ), "local-repo." + System.currentTimeMillis() ); localRepoDir = new File( System.getProperty( "java.io.tmpdir" ), "local-repo." + System.currentTimeMillis() );
localRepoDir.mkdirs(); localRepoDir.mkdirs();
@ -62,13 +63,10 @@ public class DefaultMavenProjectBuilderTest
filesToDelete.add( localRepoDir ); filesToDelete.add( localRepoDir );
} }
@Override
@AfterEach @AfterEach
public void tearDown() public void tearDown()
throws Exception throws Exception
{ {
super.tearDown();
if ( !filesToDelete.isEmpty() ) if ( !filesToDelete.isEmpty() )
{ {
for ( File file : filesToDelete ) for ( File file : filesToDelete )

View File

@ -28,7 +28,7 @@ import java.util.Properties;
import javax.inject.Inject; 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.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.apache.maven.test.PlexusExtension.getBasedir;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.lessThan; 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.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
@PlexusTest
public class PomConstructionTest public class PomConstructionTest
extends PlexusTestCase
{ {
private static String BASE_DIR = "src/test"; private static String BASE_DIR = "src/test";
@ -75,20 +76,10 @@ public class PomConstructionTest
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
testDirectory = new File( getBasedir(), BASE_POM_DIR ); testDirectory = new File( getBasedir(), BASE_POM_DIR );
new File( getBasedir(), BASE_MIXIN_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 * Will throw exception if url is empty. MNG-4050
* *

View File

@ -85,7 +85,7 @@ public class ProjectBuilderTest
configuration.setRepositorySession( mavenSession.getRepositorySession() ); configuration.setRepositorySession( mavenSession.getRepositorySession() );
ModelSource modelSource = new FileModelSource( pomFile ); ModelSource modelSource = new FileModelSource( pomFile );
ProjectBuildingResult result = 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() ); assertNotNull( result.getProject().getParentFile() );
} }
@ -100,7 +100,7 @@ public class ProjectBuilderTest
configuration.setRepositorySession( mavenSession.getRepositorySession() ); configuration.setRepositorySession( mavenSession.getRepositorySession() );
ProjectBuildingException e = assertThrows( ProjectBuildingException.class, 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(), assertThat( e.getMessage(),
containsString( "[ERROR] 'dependencies.dependency.version' for org.apache.maven.its:a:jar is missing. " containsString( "[ERROR] 'dependencies.dependency.version' for org.apache.maven.its:a:jar is missing. "
+ "@ line 9, column 17" ) ); + "@ line 9, column 17" ) );
@ -117,11 +117,11 @@ public class ProjectBuilderTest
configuration.setResolveDependencies( true ); configuration.setResolveDependencies( true );
// single project build entry point // 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() ); assertEquals( 1, result.getProject().getArtifacts().size() );
// multi projects build entry point // multi projects build entry point
List<ProjectBuildingResult> results = 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 ); configuration );
assertEquals( 1, results.size() ); assertEquals( 1, results.size() );
MavenProject mavenProject = results.get( 0 ).getProject(); MavenProject mavenProject = results.get( 0 ).getProject();
@ -139,10 +139,10 @@ public class ProjectBuilderTest
configuration.setResolveDependencies( false ); configuration.setResolveDependencies( false );
// single project build entry point // 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() ); assertEquals( 0, result.getProject().getArtifacts().size() );
// multi projects build entry point // 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() ); assertEquals( 1, results.size() );
MavenProject mavenProject = results.get( 0 ).getProject(); MavenProject mavenProject = results.get( 0 ).getProject();
assertEquals( 0, mavenProject.getArtifacts().size() ); assertEquals( 0, mavenProject.getArtifacts().size() );
@ -161,7 +161,7 @@ public class ProjectBuilderTest
MavenSession mavenSession = createMavenSession( null ); MavenSession mavenSession = createMavenSession( null );
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
configuration.setRepositorySession( mavenSession.getRepositorySession() ); 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" ); File child = new File( tempDir.toFile(), "child/pom.xml" );
// build project once // build project once
projectBuilder.build( child, configuration ); projectBuilder.build( child, configuration );
@ -199,7 +199,7 @@ public class ProjectBuilderTest
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
configuration.setRepositorySession( mavenSession.getRepositorySession() ); configuration.setRepositorySession( mavenSession.getRepositorySession() );
org.apache.maven.project.ProjectBuilder projectBuilder = 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 // single project build entry point
ProjectBuildingException ex1 = ProjectBuildingException ex1 =
@ -233,7 +233,7 @@ public class ProjectBuilderTest
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
configuration.setRepositorySession( mavenSession.getRepositorySession() ); configuration.setRepositorySession( mavenSession.getRepositorySession() );
org.apache.maven.project.ProjectBuilder projectBuilder = 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 // single project build entry point
Exception ex = assertThrows( Exception.class, () -> projectBuilder.build( pomFile, configuration ) ); Exception ex = assertThrows( Exception.class, () -> projectBuilder.build( pomFile, configuration ) );
@ -262,7 +262,7 @@ public class ProjectBuilderTest
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
configuration.setRepositorySession( mavenSession.getRepositorySession() ); configuration.setRepositorySession( mavenSession.getRepositorySession() );
org.apache.maven.project.ProjectBuilder projectBuilder = org.apache.maven.project.ProjectBuilder projectBuilder =
lookup( org.apache.maven.project.ProjectBuilder.class ); getContainer().lookup( org.apache.maven.project.ProjectBuilder.class );
// read poms separately // read poms separately
boolean parentFileWasFoundOnChild = false; boolean parentFileWasFoundOnChild = false;

View File

@ -35,6 +35,7 @@ import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RemoteRepository;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.apache.maven.test.PlexusExtension.getBasedir;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -208,8 +209,8 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase
final DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession(); final DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) ); repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) );
return new ProjectModelResolver( repoSession, null, lookup( RepositorySystem.class ), return new ProjectModelResolver( repoSession, null, getContainer().lookup( RepositorySystem.class ),
lookup( RemoteRepositoryManager.class ), getContainer().lookup( RemoteRepositoryManager.class ),
this.getRemoteRepositories(), this.getRemoteRepositories(),
ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT, null ); ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT, null );

View File

@ -19,23 +19,25 @@ package org.apache.maven.project.artifact;
* under the License. * under the License.
*/ */
import org.apache.maven.test.PlexusTestCase; import javax.inject.Inject;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.junit.jupiter.api.AfterEach; import org.apache.maven.test.PlexusTest;
import org.junit.jupiter.api.BeforeEach; import org.codehaus.plexus.PlexusContainer;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.inject.Inject; @PlexusTest
@Disabled
public class MavenMetadataSourceTest public class MavenMetadataSourceTest
extends PlexusTestCase
{ {
@Inject @Inject
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Inject
PlexusContainer container;
@Test @Test
@Disabled
public void testShouldNotCarryExclusionsOverFromDependencyToDependency() public void testShouldNotCarryExclusionsOverFromDependencyToDependency()
throws Exception throws Exception
{ {
@ -58,21 +60,21 @@ public class MavenMetadataSourceTest
dep2.setVersion( "1" ); dep2.setVersion( "1" );
dep2.setType( "jar" ); dep2.setType( "jar" );
List deps = new ArrayList(); List<Dependency> deps = new ArrayList<>();
deps.add( dep1 ); deps.add( dep1 );
deps.add( dep2 ); deps.add( dep2 );
ArtifactFactory factory = lookup( ArtifactFactory.class ); ArtifactFactory factory = container.lookup( ArtifactFactory.class );
ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE ); ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
MavenProject project = new MavenProject( new Model() ); 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() ) ) 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() public void testShouldUseCompileScopeIfDependencyScopeEmpty()
throws Exception throws Exception
{ {
/*
String groupId = "org.apache.maven"; String groupId = "org.apache.maven";
String artifactId = "maven-model"; String artifactId = "maven-model";
@ -111,21 +114,24 @@ public class MavenMetadataSourceTest
Map artifactMap = project.getArtifactMap(); Map artifactMap = project.getArtifactMap();
assertNotNull( artifactMap, "artifact-map should not be null." ); 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 ); Artifact artifact = (Artifact) artifactMap.get( key );
assertNotNull( artifact, "dependency artifact not found in map." ); 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. //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 @Test
@Disabled
public void testShouldUseInjectedTestScopeFromDependencyManagement() public void testShouldUseInjectedTestScopeFromDependencyManagement()
throws Exception throws Exception
{ {
/*
String groupId = "org.apache.maven"; String groupId = "org.apache.maven";
String artifactId = "maven-model"; String artifactId = "maven-model";
@ -163,7 +169,7 @@ public class MavenMetadataSourceTest
Map artifactMap = project.getArtifactMap(); Map artifactMap = project.getArtifactMap();
assertNotNull( artifactMap, "artifact-map should not be null." ); 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 ); Artifact artifact = (Artifact) artifactMap.get( key );
@ -172,7 +178,7 @@ public class MavenMetadataSourceTest
//check for back-propagation of default scope. //check for back-propagation of default scope.
assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() ); assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
*/
} }
*/
} }

View File

@ -20,9 +20,9 @@ package org.apache.maven.rtinfo.internal;
*/ */
import org.apache.maven.rtinfo.RuntimeInformation; import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.test.PlexusTest;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -33,21 +33,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject; import javax.inject.Inject;
@PlexusTest
public class DefaultRuntimeInformationTest public class DefaultRuntimeInformationTest
extends PlexusTestCase
{ {
@Inject @Inject
RuntimeInformation rtInfo; RuntimeInformation rtInfo;
@Override
protected void customizeContainerConfiguration(
ContainerConfiguration configuration)
{
super.customizeContainerConfiguration(configuration);
configuration.setAutoWiring(true);
configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
}
@Test @Test
public void testGetMavenVersion() public void testGetMavenVersion()
{ {

View File

@ -32,7 +32,7 @@ import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; 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.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
@ -43,10 +43,11 @@ import org.junit.jupiter.api.Test;
import javax.inject.Inject; import javax.inject.Inject;
import static org.apache.maven.test.PlexusExtension.getBasedir;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@PlexusTest
public class PomConstructionWithSettingsTest public class PomConstructionWithSettingsTest
extends PlexusTestCase
{ {
private static final String BASE_DIR = "src/test"; private static final String BASE_DIR = "src/test";
@ -64,7 +65,6 @@ public class PomConstructionWithSettingsTest
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
testDirectory = new File( getBasedir(), BASE_POM_DIR ); testDirectory = new File( getBasedir(), BASE_POM_DIR );
} }

View File

@ -23,9 +23,10 @@ import java.net.MalformedURLException;
import javax.inject.Inject; 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.ConsoleRepositoryListener;
import org.apache.maven.repository.internal.util.ConsoleTransferListener; import org.apache.maven.repository.internal.util.ConsoleTransferListener;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession; 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.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import static org.apache.maven.test.PlexusExtension.getTestFile;
@PlexusTest
public abstract class AbstractRepositoryTestCase public abstract class AbstractRepositoryTestCase
extends PlexusTestCase
{ {
@Inject @Inject
protected RepositorySystem system; protected RepositorySystem system;
@Inject
protected PlexusContainer container;
protected RepositorySystemSession session; protected RepositorySystemSession session;
@BeforeEach @BeforeEach
@Override
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp();
session = newMavenRepositorySystemSession( system ); session = newMavenRepositorySystemSession( system );
} }
public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system ) protected PlexusContainer getContainer() {
return container;
}
public static RepositorySystemSession newMavenRepositorySystemSession(RepositorySystem system )
{ {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

View File

@ -42,7 +42,7 @@ public class DefaultArtifactDescriptorReaderTest
throws Exception throws Exception
{ {
// prepare // prepare
DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) lookup( ArtifactDescriptorReader.class ); DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) getContainer().lookup( ArtifactDescriptorReader.class );
RepositoryEventDispatcher eventDispatcher = mock( RepositoryEventDispatcher.class ); RepositoryEventDispatcher eventDispatcher = mock( RepositoryEventDispatcher.class );

View File

@ -202,8 +202,8 @@ public final class DefaultModelResolverTest extends AbstractRepositoryTestCase
private ModelResolver newModelResolver() throws ComponentLookupException, MalformedURLException private ModelResolver newModelResolver() throws ComponentLookupException, MalformedURLException
{ {
return new DefaultModelResolver( this.session, null, this.getClass().getName(), return new DefaultModelResolver( this.session, null, this.getClass().getName(),
lookup( ArtifactResolver.class ), lookup( VersionRangeResolver.class ), getContainer().lookup( ArtifactResolver.class ), getContainer().lookup( VersionRangeResolver.class ),
lookup( RemoteRepositoryManager.class ), getContainer().lookup( RemoteRepositoryManager.class ),
Arrays.asList( newTestRepository() ) ); Arrays.asList( newTestRepository() ) );
} }

View File

@ -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;
}

View File

@ -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<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
ExtensionContext extensionContext )
{
Class<?> testClass = extensionContext.getRequiredTestClass();
try
{
List<Method> 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<Method> getParametersMethods( Class<?> testClass )
{
List<Method> 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<Extension> getAdditionalExtensions()
{
return Arrays.asList(
( TestInstancePostProcessor ) this::postProcessTestInstance );
}
protected void postProcessTestInstance( Object testInstance, ExtensionContext context ) throws Exception
{
Class<?> clazz = testInstance.getClass();
List<Field> 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<Class<?>> hierarchy( Class<?> clazz )
{
Class<?> superclass = clazz.getSuperclass();
return Stream.concat( Stream.of( clazz ), superclass != null ? hierarchy( superclass ) : Stream.empty() );
}
}
}

View File

@ -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}";
}

View File

@ -50,8 +50,9 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.DefaultContext; import org.codehaus.plexus.context.DefaultContext;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.BeforeEach; 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 * 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:michal@codehaus.org">Michal Maczka</a> * @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @author Guillaume Nodet * @author Guillaume Nodet
*/ */
public abstract class PlexusTestCase public class PlexusExtension implements BeforeEachCallback, AfterEachCallback
{ {
private ExtensionContext context;
private PlexusContainer container; private PlexusContainer container;
private static String basedir; private static String basedir;
@BeforeEach @Override
public void setUp() public void beforeEach( ExtensionContext context )
throws Exception throws Exception
{ {
basedir = getBasedir(); basedir = getBasedir();
this.context = context;
getContainer().addComponent( getContainer(), PlexusContainer.class.getName() );
( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) ); binder -> binder.requestInjection( context.getRequiredTestInstance() ) );
} }
@SuppressWarnings( "ResultOfMethodCallIgnored" ) @SuppressWarnings( "ResultOfMethodCallIgnored" )
@ -161,8 +166,8 @@ public abstract class PlexusTestCase
return null; return null;
} }
@AfterEach @Override
public void tearDown() public void afterEach( ExtensionContext context )
throws Exception throws Exception
{ {
if ( container != null ) if ( container != null )
@ -173,7 +178,7 @@ public abstract class PlexusTestCase
} }
} }
protected PlexusContainer getContainer() public PlexusContainer getContainer()
{ {
if ( container == null ) if ( container == null )
{ {
@ -211,17 +216,28 @@ public abstract class PlexusTestCase
*/ */
protected String getConfigurationName( String subname ) 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 ) protected InputStream getResourceAsStream( String resource )
{ {
return getClass().getResourceAsStream( resource ); return context.getRequiredTestClass().getResourceAsStream( resource );
} }
protected ClassLoader getClassLoader() protected ClassLoader getClassLoader()
{ {
return getClass().getClassLoader(); return context.getRequiredTestClass().getClassLoader();
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -313,7 +329,7 @@ public abstract class PlexusTestCase
public String getTestConfiguration() public String getTestConfiguration()
{ {
return getTestConfiguration( getClass() ); return getTestConfiguration( context.getRequiredTestClass() );
} }
public static String getTestConfiguration( Class<?> clazz ) public static String getTestConfiguration( Class<?> clazz )

View File

@ -27,11 +27,12 @@ import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
/** /**
* Parameterized * Plexus test
*/ */
@Target( { ElementType.ANNOTATION_TYPE, ElementType.TYPE } )
@Retention( RetentionPolicy.RUNTIME ) @Retention( RetentionPolicy.RUNTIME )
@ExtendWith( ParameterizedExtension.class ) @ExtendWith( PlexusExtension.class )
public @interface Parameterized @Target( ElementType.TYPE )
public @interface PlexusTest
{ {
} }

View File

@ -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
{
}

View File

@ -22,34 +22,18 @@ package org.apache.maven.xml.sax.ext;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import java.util.Arrays; import org.junit.jupiter.params.ParameterizedTest;
import java.util.Collection; 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; import org.xml.sax.ext.LexicalHandler;
@Parameterized
public class CommentRenormalizerTest public class CommentRenormalizerTest
{ {
private LexicalHandler lexicalHandler = mock( LexicalHandler.class ); private LexicalHandler lexicalHandler = mock( LexicalHandler.class );
@Parameter @ParameterizedTest
private String lineSeparator; @ValueSource(strings = {"\n", "\r\n", "\r" })
public void singleLine(String lineSeparator)
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ "\n" },
{ "\r\n" },
{ "\r" }
});
}
@Test
public void singleLine()
throws Exception throws Exception
{ {
CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator ); CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator );
@ -61,8 +45,9 @@ public class CommentRenormalizerTest
verify( lexicalHandler ).comment( ch, 0, ch.length ); verify( lexicalHandler ).comment( ch, 0, ch.length );
} }
@Test @ParameterizedTest
public void multiLine() @ValueSource(strings = {"\n", "\r\n", "\r" })
public void multiLine(String lineSeparator)
throws Exception throws Exception
{ {
CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator ); CommentRenormalizer commentRenormalizer = new CommentRenormalizer( lexicalHandler, lineSeparator );