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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]