This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch MNG-7035-maven5 in repository https://gitbox.apache.org/repos/asf/maven.git
commit f75d1d78027123e1fec9cffc46cc012872df573b Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Fri Jan 8 14:16:28 2021 +0100 Remove more unneeded lookups --- .../AbstractArtifactComponentTestCase.java | 26 ++++------------------ .../artifact/deployer/ArtifactDeployerTest.java | 10 --------- .../artifact/installer/ArtifactInstallerTest.java | 10 --------- .../maven/repository/MirrorProcessorTest.java | 10 +-------- .../legacy/DefaultUpdateCheckManagerTest.java | 7 ++++-- .../resolver/DefaultArtifactCollectorTest.java | 17 +++++--------- .../conflict/AbstractConflictResolverTest.java | 2 +- .../DefaultClasspathTransformationTest.java | 5 ++++- .../metadata/DefaultGraphConflictResolverTest.java | 6 ++--- .../internal/LifecycleDependencyResolverTest.java | 8 ------- .../internal/AbstractRepositoryTestCase.java | 14 +++--------- .../internal/DefaultVersionResolverTest.java | 22 +++--------------- 12 files changed, 29 insertions(+), 108 deletions(-) diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 70b81d7..7ad6719 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.List; import javax.inject.Inject; +import javax.inject.Named; import org.apache.maven.test.PlexusTestCase; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -88,6 +89,9 @@ public abstract class AbstractArtifactComponentTestCase @Inject LegacySupport legacySupport; + @Inject @Named( "default" ) + ArtifactRepositoryLayout repoLayout; + @Before public void setUp() throws Exception @@ -101,16 +105,6 @@ public abstract class AbstractArtifactComponentTestCase legacySupport.setSession( session ); } - @After - @Override - public void tearDown() - throws Exception - { - release( artifactFactory ); - - super.tearDown(); - } - protected abstract String component(); /** @@ -127,9 +121,6 @@ public abstract class AbstractArtifactComponentTestCase f.createNewFile(); - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, null, null ); } @@ -146,9 +137,6 @@ public abstract class AbstractArtifactComponentTestCase File f = new File( getBasedir(), path ); - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + f.getPath(), repoLayout, null, null ); } @@ -160,9 +148,6 @@ public abstract class AbstractArtifactComponentTestCase File f = new File( getBasedir(), path ); - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() ); @@ -171,9 +156,6 @@ public abstract class AbstractArtifactComponentTestCase protected ArtifactRepository badRemoteRepository() throws Exception { - ArtifactRepositoryLayout repoLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return artifactRepositoryFactory.createArtifactRepository( "test", "http://foo.bar/repository", repoLayout, null, null ); } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 6295a22..e1459d8 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -42,16 +42,6 @@ public class ArtifactDeployerTest @Inject private ArtifactDeployer artifactDeployer; - @Before - @Override - public void setUp() - throws Exception - { - super.setUp(); - - artifactDeployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE ); - } - protected String component() { return "deployer"; diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java index 3e22ffd..7ba6b33 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java @@ -37,16 +37,6 @@ public class ArtifactInstallerTest @Inject private ArtifactInstaller artifactInstaller; - @Before - @Override - public void setUp() - throws Exception - { - super.setUp(); - - artifactInstaller = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE ); - } - protected String component() { return "installer"; diff --git a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java index 9d7c7ad..b48bdd6 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java @@ -47,18 +47,10 @@ public class MirrorProcessorTest { @Inject private DefaultMirrorSelector mirrorSelector; + @Inject private ArtifactRepositoryFactory repositorySystem; - @Before - public void setUp() - throws Exception - { - super.setUp(); - mirrorSelector = (DefaultMirrorSelector) lookup( MirrorSelector.class ); - repositorySystem = lookup( ArtifactRepositoryFactory.class ); - } - @Test public void testExternalURL() { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java index 4f1bede..fe65393 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManagerTest.java @@ -21,6 +21,8 @@ package org.apache.maven.repository.legacy; import java.io.File; +import javax.inject.Inject; + import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -42,6 +44,9 @@ public class DefaultUpdateCheckManagerTest extends AbstractArtifactComponentTestCase { + @Inject + private ArtifactFactory artifactFactory; + DefaultUpdateCheckManager updateCheckManager; @Override @@ -233,8 +238,6 @@ public class DefaultUpdateCheckManagerTest @Test public void testArtifactTouchFileName() throws Exception { - ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - ArtifactRepository localRepository = localRepository(); Artifact a = artifactFactory.createArtifactWithClassifier( "groupdId", "a", "0.0.1-SNAPSHOT", "jar", null ); 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 80de492..5927030 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 @@ -29,6 +29,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.inject.Inject; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -52,6 +54,7 @@ import org.codehaus.plexus.PlexusConstants; import org.apache.maven.test.PlexusTestCase; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -67,8 +70,10 @@ import static org.junit.Assert.assertTrue; public class DefaultArtifactCollectorTest extends PlexusTestCase { + @Inject private LegacyArtifactCollector artifactCollector; + @Inject private ArtifactFactory artifactFactory; private ArtifactSpec projectArtifact; @@ -85,22 +90,10 @@ public class DefaultArtifactCollectorTest super.setUp(); source = new Source(); - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - artifactCollector = lookup( LegacyArtifactCollector.class ); projectArtifact = createArtifactSpec( "project", "1.0", null ); } - @After - @Override - public void tearDown() - throws Exception - { - artifactCollector = null; - artifactFactory = null; - super.tearDown(); - } - @Test @Ignore("works, but we don't fail on cycles presently") public void testCircularDependencyNotIncludingCurrentProject() 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 1a5eeab..87fde6a 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 @@ -86,7 +86,7 @@ public abstract class AbstractConflictResolverTest { super.setUp(); - conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint ); + conflictResolver = lookup( ConflictResolver.ROLE, roleHint ); a1 = createArtifact( "a", "1.0" ); a2 = createArtifact( "a", "2.0" ); diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java index 0da1be9..10d39bc 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultClasspathTransformationTest.java @@ -15,6 +15,9 @@ package org.apache.maven.repository.metadata; * the License. */ +import javax.inject.Inject; +import javax.inject.Named; + import org.apache.maven.artifact.ArtifactScopeEnum; import org.apache.maven.test.PlexusTestCase; import org.junit.Before; @@ -32,6 +35,7 @@ import static org.junit.Assert.assertNotNull; public class DefaultClasspathTransformationTest extends PlexusTestCase { + @Inject ClasspathTransformation transform; MetadataGraph graph; @@ -46,7 +50,6 @@ extends PlexusTestCase public void setUp() throws Exception { super.setUp(); - transform = (ClasspathTransformation) lookup( ClasspathTransformation.ROLE, "default" ); graph = new MetadataGraph( 4, 3 ); /* diff --git a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java index cba9491..75663dc 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolverTest.java @@ -15,6 +15,8 @@ package org.apache.maven.repository.metadata; * the License. */ +import javax.inject.Inject; + import org.apache.maven.artifact.ArtifactScopeEnum; import org.apache.maven.test.PlexusTestCase; import org.codehaus.plexus.logging.Logger; @@ -33,8 +35,7 @@ import static org.junit.Assert.assertNotNull; public class DefaultGraphConflictResolverTest extends PlexusTestCase { - Logger log; - + @Inject GraphConflictResolver resolver; MetadataGraph graph; @@ -49,7 +50,6 @@ extends PlexusTestCase public void setUp() throws Exception { super.setUp(); - resolver = (GraphConflictResolver) lookup( GraphConflictResolver.ROLE, "default" ); /* * v2 diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java index 2cd28b2..7689515 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java @@ -48,14 +48,6 @@ public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentT return null; } - @Before - public void setUp() - throws Exception - { - super.setUp(); - resolver = lookup( LifecycleDependencyResolver.class ); - } - @Test public void testCachedReactorProjectDependencies() throws Exception { diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java index 54f4f4c..699a172 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/AbstractRepositoryTestCase.java @@ -21,6 +21,8 @@ package org.apache.maven.repository.internal; import java.net.MalformedURLException; +import javax.inject.Inject; + import org.apache.maven.test.PlexusTestCase; import org.apache.maven.repository.internal.util.ConsoleRepositoryListener; import org.apache.maven.repository.internal.util.ConsoleTransferListener; @@ -37,6 +39,7 @@ import org.junit.Before; public abstract class AbstractRepositoryTestCase extends PlexusTestCase { + @Inject protected RepositorySystem system; protected RepositorySystemSession session; @@ -47,20 +50,9 @@ public abstract class AbstractRepositoryTestCase throws Exception { super.setUp(); - system = lookup( RepositorySystem.class ); session = newMavenRepositorySystemSession( system ); } - @After - @Override - public void tearDown() - throws Exception - { - session = null; - system = null; - super.tearDown(); - } - public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system ) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java index f02307e..03d8eb5 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultVersionResolverTest.java @@ -19,6 +19,8 @@ package org.apache.maven.repository.internal; * under the License. */ +import javax.inject.Inject; + import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.impl.VersionResolver; @@ -33,27 +35,9 @@ import static org.junit.Assert.assertEquals; public class DefaultVersionResolverTest extends AbstractRepositoryTestCase { + @Inject private DefaultVersionResolver versionResolver; - @Before - @Override - public void setUp() - throws Exception - { - super.setUp(); - // be sure we're testing the right class, i.e. DefaultVersionResolver.class - versionResolver = (DefaultVersionResolver) lookup( VersionResolver.class, "default" ); - } - - @After - @Override - public void tearDown() - throws Exception - { - versionResolver = null; - super.tearDown(); - } - @Test public void testResolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws Exception