You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "slawekjaranowski (via GitHub)" <gi...@apache.org> on 2026/01/10 23:04:36 UTC

[PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

slawekjaranowski opened a new pull request, #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574

   - Next part
   - bump plugin-testing to 3.5.0
   - cleanups after parent
   
   Following this checklist to help us incorporate your
   contribution quickly and easily:
   
   - [ ] Your pull request should address just one issue, without pulling in other changes.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Each commit in the pull request should have a meaningful subject line and body.
     Note that commits might be squashed by a maintainer on merge.
   - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
     This may not always be possible but is a best-practice.
   - [ ] Run `mvn verify` to make sure basic checks pass.
     A more thorough check will be performed on your pull request automatically.
   - [ ] You have run the integration tests successfully (`mvn -Prun-its verify`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
   - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574#discussion_r2684030959


##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java:
##########
@@ -18,86 +18,70 @@
  */
 package org.apache.maven.plugins.dependency.fromConfiguration;
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.LegacySupport;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
+import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
 import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
 import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
-public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase {

Review Comment:
   There are still test based on it ...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574#discussion_r2701007408


##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java:
##########
@@ -107,22 +101,22 @@ public void testGetArtifactItems() throws Exception {
 
         mojo.setArtifactItems(list);
 
-        ArtifactItem result = getSingleArtifactItem(false);
+        ArtifactItem result = getSingleArtifactItem(mojo);
         assertEquals(mojo.getOutputDirectory(), result.getOutputDirectory());
 
         File output = new File(mojo.getOutputDirectory(), "override");
         item.setOutputDirectory(output);
-        result = getSingleArtifactItem(false);
+        result = getSingleArtifactItem(mojo);
         assertEquals(output, result.getOutputDirectory());
     }
 
-    public void assertMarkerFiles(Collection<ArtifactItem> items, boolean exist) {
+    private void assertMarkerFiles(UnpackMojo mojo, Collection<ArtifactItem> items, boolean exist) {

Review Comment:
   I will leave it as is, that is a simple method, is more readable to have it in test class instead of creating utils for it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574#issuecomment-3763277734

   > Should we rename the test classes, so that they have a Test suffix?
   There are many tests to rename .... we can do it in separate PR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574#discussion_r2684032315


##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java:
##########
@@ -107,22 +101,22 @@ public void testGetArtifactItems() throws Exception {
 
         mojo.setArtifactItems(list);
 
-        ArtifactItem result = getSingleArtifactItem(false);
+        ArtifactItem result = getSingleArtifactItem(mojo);
         assertEquals(mojo.getOutputDirectory(), result.getOutputDirectory());
 
         File output = new File(mojo.getOutputDirectory(), "override");
         item.setOutputDirectory(output);
-        result = getSingleArtifactItem(false);
+        result = getSingleArtifactItem(mojo);
         assertEquals(output, result.getOutputDirectory());
     }
 
-    public void assertMarkerFiles(Collection<ArtifactItem> items, boolean exist) {
+    private void assertMarkerFiles(UnpackMojo mojo, Collection<ArtifactItem> items, boolean exist) {

Review Comment:
   I wil check after finish



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "sparsick (via GitHub)" <gi...@apache.org>.
sparsick commented on code in PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574#discussion_r2681683103


##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java:
##########
@@ -107,22 +101,22 @@ public void testGetArtifactItems() throws Exception {
 
         mojo.setArtifactItems(list);
 
-        ArtifactItem result = getSingleArtifactItem(false);
+        ArtifactItem result = getSingleArtifactItem(mojo);
         assertEquals(mojo.getOutputDirectory(), result.getOutputDirectory());
 
         File output = new File(mojo.getOutputDirectory(), "override");
         item.setOutputDirectory(output);
-        result = getSingleArtifactItem(false);
+        result = getSingleArtifactItem(mojo);
         assertEquals(output, result.getOutputDirectory());
     }
 
-    public void assertMarkerFiles(Collection<ArtifactItem> items, boolean exist) {
+    private void assertMarkerFiles(UnpackMojo mojo, Collection<ArtifactItem> items, boolean exist) {

Review Comment:
   Is it the same private method like in `TestIncludeExcludeUnpackMojo`? If we have more such assert method, we should move them to a separate Assertion class.



##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java:
##########
@@ -18,86 +18,70 @@
  */
 package org.apache.maven.plugins.dependency.fromConfiguration;
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.LegacySupport;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
+import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
 import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
 import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
-public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase {
-    private static final String PACKED_FILE = "test.zip";
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
-    private static final String UNPACKED_FILE_PREFIX = "test";
+@MojoTest(realRepositorySession = true)
+@Basedir("/unit/unpack-dependencies-test")
+@MojoParameter(name = "artifact", value = "test:test:1.0")
+class TestIncludeExcludeUnpackMojo {
 
-    private static final String UNPACKED_FILE_SUFFIX = ".txt";
+    @TempDir
+    private File tempDir;
 
-    private static final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE;
+    private DependencyArtifactStubFactory stubFactory;
 
-    private UnpackMojo mojo;
-
-    @Override
-    protected String getTestDirectoryName() {
-        return "unpack";
-    }
-
-    @Override
-    protected boolean shouldCreateFiles() {
-        return true;
-    }
-
-    @Override
-    protected boolean shouldUseFlattenedPath() {
-        return false;
-    }
+    @Inject
+    private MavenSession session;
 
-    @Override
-    protected void setUp() throws Exception {
-        // required for mojo lookups to work
-        super.setUp();
+    @Inject
+    private MavenProject project;
 
-        MavenProject project = new DependencyProjectStub();
-        getContainer().addComponent(project, MavenProject.class.getName());
-
-        MavenSession session = newMavenSession(project);
-        getContainer().addComponent(session, MavenSession.class.getName());
+    private static final String UNPACKED_FILE_PREFIX = "test";
 
-        File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
-        mojo = (UnpackMojo) lookupMojo("unpack", testPom);
-        mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
+    private static final String UNPACKED_FILE_SUFFIX = ".txt";
 
-        // I'm using one file repeatedly to archive so I can test the name
-        // programmatically.
-        stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
-        Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
-        ArtifactItem item = new ArtifactItem(artifact);
-        List<ArtifactItem> list = new ArrayList<>(1);
-        list.add(item);
-        assertNotNull(mojo);
-        assertNotNull(mojo.getProject());
+    @BeforeEach
+    void setUp() throws Exception {
+        stubFactory = new DependencyArtifactStubFactory(tempDir, true, false);
+        stubFactory.setSrcFile(MojoExtension.getTestFile("test.zip"));
+        stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
 
-        mojo.setMarkersDirectory(new File(this.testDir, "markers"));
-        mojo.setArtifactItems(list);
+        session.getRequest().setLocalRepositoryPath(new File(tempDir, "localTestRepo"));
 
-        LegacySupport legacySupport = lookup(LegacySupport.class);
-        legacySupport.setSession(session);
-        installLocalRepository(legacySupport);
+        project.getBuild().setDirectory(new File(tempDir, "target").getAbsolutePath());
     }
 
-    public void assertMarkerFiles(Collection<ArtifactItem> items, boolean exist) {
+    private void assertMarkerFiles(UnpackMojo mojo, Collection<ArtifactItem> items) {
         for (ArtifactItem item : items) {
-            assertMarkerFile(exist, item);
+            assertMarkerFile(mojo, true, item);
         }
     }
 
-    public void assertMarkerFile(boolean val, ArtifactItem item) {
+    private void assertMarkerFile(UnpackMojo mojo, boolean val, ArtifactItem item) {

Review Comment:
   choose a better name for the parameter `val`. Maybe `exists`?
   



##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java:
##########
@@ -18,86 +18,70 @@
  */
 package org.apache.maven.plugins.dependency.fromConfiguration;
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.LegacySupport;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
+import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
 import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
 import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
-public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase {

Review Comment:
   Can `AbstractDependencyMojoTestCase` be deleted? IMHO after this refactoring it should be possible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski merged PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Migration to JUnit 5 - avoid using AbstractMojoTestCase [maven-dependency-plugin]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1574:
URL: https://github.com/apache/maven-dependency-plugin/pull/1574#discussion_r2701008381


##########
src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java:
##########
@@ -18,86 +18,70 @@
  */
 package org.apache.maven.plugins.dependency.fromConfiguration;
 
+import javax.inject.Inject;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.LegacySupport;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
+import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
 import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
 import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
-public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase {

Review Comment:
   removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org