[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.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:jason@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() );

View File

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

View File

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

View File

@ -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: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.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()
{

View File

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

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.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;

View File

@ -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() );
*/
}
*/
}

View File

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

View File

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

View File

@ -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
*/

View File

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

View File

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

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.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.maczka@dimatics.com">Michal Maczka</a>
*/
@PlexusTest
public class DefaultWagonManagerTest
extends PlexusTestCase
{
@Inject
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.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;

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.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:brett@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 );

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.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:markhobson@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()

View File

@ -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:oleg@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

View File

@ -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:oleg@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<

View File

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

View File

@ -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();

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

@ -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", //

View File

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

View File

@ -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
// ----------------------------------------------------------------------

View File

@ -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 )

View File

@ -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
*

View File

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

View File

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

View File

@ -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() );
*/
}
*/
}

View File

@ -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()
{

View File

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

View File

@ -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();

View File

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

View File

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

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.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:michal@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 )

View File

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

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