From b962ff361aee64a291db588e9f88d86c5f9dee0c Mon Sep 17 00:00:00 2001 From: Joseph Walton Date: Mon, 24 Jun 2019 22:54:06 +1000 Subject: [PATCH] [MNG-5577] Simplify tests to reduce use of wiring. - Reduce the use of wiring in unit tests - Enable class scanning for tests that require it. - Remove test and wiring that's not used. --- .../factory/DefaultArtifactFactoryTest.java | 10 +++++++ .../transform/TransformationManagerTest.java | 10 +++++++ .../maven/project/ProjectClasspathTest.java | 13 +++++++-- .../maven/project/TestProjectBuilder.java | 28 ------------------- .../legacy/DefaultWagonManagerTest.java | 10 +++++++ .../DefaultArtifactCollectorTest.java | 10 +++++++ .../AbstractConflictResolverTest.java | 10 +++++++ ...aultGraphConflictResolutionPolicyTest.java | 7 +++-- ...DefaultMavenExecutionRequestPopulator.java | 2 ++ .../DefaultBeanConfiguratorTest.java | 8 ++++-- .../lifecycle/DefaultLifecyclesTest.java | 10 +++++++ .../maven/project/TestMetadataSource.java | 10 ++++--- .../DefaultMavenMetadataCacheTest.java | 2 +- .../DefaultProjectArtifactsCacheTest.java | 7 +++-- .../repository/LegacyRepositoryLayout.java | 7 +++-- .../TestRepositoryConnectorFactory.java | 7 +++-- .../repository/TestRepositorySystem.java | 22 ++++++++++----- .../DefaultRuntimeInformationTest.java | 11 ++++++++ .../org/apache/maven/cli/MavenCliTest.java | 19 +++++++++++-- 19 files changed, 145 insertions(+), 58 deletions(-) diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java index 0d109acbd4..a90c33b66b 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java @@ -21,12 +21,22 @@ package org.apache.maven.artifact.factory; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.VersionRange; +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; public class DefaultArtifactFactoryTest extends PlexusTestCase { + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + public void testPropagationOfSystemScopeRegardlessOfInheritedScope() throws Exception { ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java index 38450929f3..45b4c00ecd 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java @@ -21,12 +21,22 @@ 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.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; /** @author Jason van Zyl */ public class TransformationManagerTest extends PlexusTestCase { + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + public void testTransformationManager() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index d7ae86e697..10825d2c82 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -24,6 +24,8 @@ import java.io.File; import org.apache.maven.artifact.Artifact; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.eclipse.aether.impl.ArtifactDescriptorReader; import org.eclipse.aether.impl.ArtifactResolver; @@ -32,6 +34,14 @@ public class ProjectClasspathTest { static final String dir = "projects/scope/"; + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + public void setUp() throws Exception { @@ -41,9 +51,6 @@ public class ProjectClasspathTest projectBuilder = lookup( ProjectBuilder.class, "classpath" ); - // the metadata source looks up the default impl, so we have to trick it - getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" ); - repositorySystem = lookup( RepositorySystem.class ); } diff --git a/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java index 754487f47e..bb6a20d1f9 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ b/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -16,10 +16,8 @@ package org.apache.maven.project; */ import java.io.File; -import java.io.FileNotFoundException; import java.util.Collections; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.codehaus.plexus.component.annotations.Component; @@ -28,32 +26,6 @@ public class TestProjectBuilder extends DefaultProjectBuilder { - @Override - public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request ) - throws ProjectBuildingException - { - if ( "maven-test".equals( artifact.getGroupId() ) ) - { - String scope = artifact.getArtifactId().substring( "scope-".length() ); - - try - { - artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml" ) ); - } - catch ( FileNotFoundException e ) - { - throw new IllegalStateException( "Missing test POM for " + artifact ); - } - } - if ( artifact.getFile() == null ) - { - MavenProject project = new MavenProject(); - project.setArtifact( artifact ); - return new DefaultProjectBuildingResult( project, null, null ); - } - return build( artifact.getFile(), request ); - } - @Override public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration ) throws ProjectBuildingException diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index aa5dd68ee8..1b3cb7992e 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -43,6 +43,8 @@ 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.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; @@ -60,6 +62,14 @@ public class DefaultWagonManagerTest private ArtifactRepositoryFactory artifactRepositoryFactory; + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + protected void setUp() throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java index 3f3a926fdf..5d88702136 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java @@ -37,6 +37,8 @@ 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.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import java.util.ArrayList; @@ -67,6 +69,14 @@ public class DefaultArtifactCollectorTest private static final String GROUP_ID = "test"; + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + @Override protected void setUp() throws Exception diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java index 12a0c57e5d..1b4f4f4334 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/conflict/AbstractConflictResolverTest.java @@ -26,6 +26,8 @@ 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.repository.legacy.resolver.conflict.ConflictResolver; +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import java.util.Collections; @@ -66,6 +68,14 @@ public abstract class AbstractConflictResolverTest // TestCase methods ------------------------------------------------------- + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + /* * @see junit.framework.TestCase#setUp() */ diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java index 31832c3390..89c0116d52 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicyTest.java @@ -17,7 +17,8 @@ package org.apache.maven.repository.metadata; import org.apache.maven.repository.metadata.GraphConflictResolutionPolicy; import org.apache.maven.repository.metadata.MetadataGraphEdge; -import org.codehaus.plexus.PlexusTestCase; + +import junit.framework.TestCase; /** * @@ -26,7 +27,7 @@ import org.codehaus.plexus.PlexusTestCase; */ public class DefaultGraphConflictResolutionPolicyTest -extends PlexusTestCase + extends TestCase { GraphConflictResolutionPolicy policy; MetadataGraphEdge e1; @@ -37,7 +38,7 @@ extends PlexusTestCase protected void setUp() throws Exception { super.setUp(); - policy = (GraphConflictResolutionPolicy) lookup( GraphConflictResolutionPolicy.ROLE, "default" ); + policy = new DefaultGraphConflictResolutionPolicy(); e1 = new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ); e2 = new MetadataGraphEdge( "1.2", true, null, null, 3, 2 ); e3 = new MetadataGraphEdge( "1.2", true, null, null, 2, 3 ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index 6951c91820..399ee34483 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -28,6 +28,7 @@ import java.util.Set; import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Singleton; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -53,6 +54,7 @@ import org.codehaus.plexus.util.StringUtils; * Assists in populating an execution request for invocation of Maven. */ @Named +@Singleton public class DefaultMavenExecutionRequestPopulator implements MavenExecutionRequestPopulator { diff --git a/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java b/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java index 3fca9658c6..a0588a2c9e 100644 --- a/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java +++ b/maven-core/src/test/java/org/apache/maven/configuration/DefaultBeanConfiguratorTest.java @@ -23,16 +23,18 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.configuration.internal.DefaultBeanConfigurator; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import junit.framework.TestCase; + /** * @author Benjamin Bentmann */ public class DefaultBeanConfiguratorTest - extends PlexusTestCase + extends TestCase { private BeanConfigurator configurator; @@ -43,7 +45,7 @@ public class DefaultBeanConfiguratorTest { super.setUp(); - configurator = lookup( BeanConfigurator.class ); + configurator = new DefaultBeanConfigurator(); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java index 690532c77d..d025cdd939 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java @@ -14,6 +14,8 @@ */ package org.apache.maven.lifecycle; +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.component.annotations.Requirement; @@ -29,6 +31,14 @@ public class DefaultLifecyclesTest @Requirement private DefaultLifecycles defaultLifeCycles; + @Override + protected void customizeContainerConfiguration( + ContainerConfiguration configuration) + { + super.customizeContainerConfiguration(configuration); + configuration.setAutoWiring(true); + configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); + } protected void setUp() throws Exception diff --git a/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java b/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java index 67c0037b1c..d39f4c6eda 100644 --- a/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java +++ b/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java @@ -21,16 +21,18 @@ package org.apache.maven.project; import java.util.List; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.project.artifact.MavenMetadataSource; -import org.codehaus.plexus.component.annotations.Component; @SuppressWarnings( "deprecation" ) -@Component( role = ArtifactMetadataSource.class, hint = "classpath" ) +@Named( "classpath" ) +@Singleton public class TestMetadataSource extends MavenMetadataSource { @@ -48,4 +50,4 @@ public class TestMetadataSource return rg; } -} \ No newline at end of file +} diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java index c50cd70bd1..c039934692 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java @@ -44,7 +44,7 @@ public class DefaultMavenMetadataCacheTest throws Exception { super.setUp(); - repositorySystem = new TestRepositorySystem(); + repositorySystem = new TestRepositorySystem( null, null ); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java index 166c068b81..dfc4d8010c 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCacheTest.java @@ -26,9 +26,10 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; -import org.codehaus.plexus.PlexusTestCase; -public class DefaultProjectArtifactsCacheTest extends PlexusTestCase +import junit.framework.TestCase; + +public class DefaultProjectArtifactsCacheTest extends TestCase { private ProjectArtifactsCache cache; @@ -38,7 +39,7 @@ public class DefaultProjectArtifactsCacheTest extends PlexusTestCase throws Exception { super.setUp(); - cache = lookup( ProjectArtifactsCache.class ); + cache = new DefaultProjectArtifactsCache(); } public void testProjectDependencyOrder() throws Exception diff --git a/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java b/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java index 77a6baefbf..bef400ed05 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java +++ b/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java @@ -1,5 +1,8 @@ package org.apache.maven.repository; +import javax.inject.Named; +import javax.inject.Singleton; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -24,12 +27,12 @@ import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.codehaus.plexus.component.annotations.Component; /** * @author jdcasey */ -@Component(role=ArtifactRepositoryLayout.class, hint="legacy") +@Named( "legacy" ) +@Singleton public class LegacyRepositoryLayout implements ArtifactRepositoryLayout { diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java index 17fd43f925..1f41e09e1a 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java @@ -19,7 +19,9 @@ package org.apache.maven.repository; * under the License. */ -import org.codehaus.plexus.component.annotations.Component; +import javax.inject.Named; +import javax.inject.Singleton; + import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.spi.connector.RepositoryConnector; @@ -29,7 +31,8 @@ import org.eclipse.aether.transfer.NoRepositoryConnectorException; /** * @author Benjamin Bentmann */ -@Component( role = RepositoryConnectorFactory.class, hint = "test" ) +@Named( "test" ) +@Singleton public class TestRepositoryConnectorFactory implements RepositoryConnectorFactory { diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java index 0e054c6a76..a3c1c0d61c 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java @@ -26,6 +26,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.InvalidRepositoryException; @@ -48,8 +52,6 @@ import org.apache.maven.project.artifact.ArtifactWithDependencies; import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystemSession; @@ -57,16 +59,22 @@ import org.eclipse.aether.RepositorySystemSession; /** * @author Benjamin Bentmann */ -@Component( role = RepositorySystem.class ) +@Named +@Singleton public class TestRepositorySystem implements RepositorySystem { - @Requirement - private ModelReader modelReader; + private final ModelReader modelReader; - @Requirement - private ArtifactFactory artifactFactory; + private final ArtifactFactory artifactFactory; + + @Inject + public TestRepositorySystem( ModelReader modelReader, ArtifactFactory artifactFactory ) + { + this.modelReader = modelReader; + this.artifactFactory = artifactFactory; + } public ArtifactRepository buildArtifactRepository( Repository repository ) throws InvalidRepositoryException diff --git a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java index d367fb91fd..68fbcb14e3 100644 --- a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java +++ b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java @@ -20,12 +20,23 @@ package org.apache.maven.rtinfo.internal; */ import org.apache.maven.rtinfo.RuntimeInformation; +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; public class DefaultRuntimeInformationTest extends PlexusTestCase { + @Override + protected void customizeContainerConfiguration( + ContainerConfiguration configuration) + { + super.customizeContainerConfiguration(configuration); + configuration.setAutoWiring(true); + configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); + } + public void testGetMavenVersion() throws Exception { diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index 5f4c5b69a7..173b78c78a 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -24,12 +24,13 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; -import static org.mockito.Mockito.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import java.io.File; +import java.util.Collections; import org.apache.commons.cli.ParseException; import org.apache.maven.Maven; @@ -37,12 +38,17 @@ import org.apache.maven.eventspy.internal.EventSpyDispatcher; import org.apache.maven.shared.utils.logging.MessageUtils; import org.apache.maven.toolchain.building.ToolchainsBuildingRequest; import org.apache.maven.toolchain.building.ToolchainsBuildingResult; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; +import org.eclipse.sisu.plexus.PlexusBeanModule; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InOrder; +import com.google.inject.Binder; +import com.google.inject.Module; + public class MavenCliTest { private MavenCli cli; @@ -314,8 +320,17 @@ public class MavenCliTest @Override protected void customizeContainer(PlexusContainer container) { super.customizeContainer(container); - container.addComponent(eventSpyDispatcherMock, "org.apache.maven.eventspy.internal.EventSpyDispatcher"); container.addComponent(mock(Maven.class), "org.apache.maven.Maven"); + + ((DefaultPlexusContainer)container).addPlexusInjector(Collections.emptyList(), + new Module() + { + public void configure( final Binder binder ) + { + binder.bind( EventSpyDispatcher.class ).toInstance( eventSpyDispatcherMock ); + } + } + ); } };