Skip to content

Commit 4e021c0

Browse files
Migration to JUnit 5 - avoid using AbstractMojoTestCase (#1574)
* Migration to JUnit 5 - avoid using AbstractMojoTestCase - bump plugin-testing to 3.5.0 - cleanups after parent
1 parent 933e203 commit 4e021c0

40 files changed

+1263
-2577
lines changed

pom.xml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ under the License.
9797
<jettyVersion>9.4.58.v20250814</jettyVersion>
9898
<mockito.version>4.11.0</mockito.version>
9999
<plexus-archiver.version>4.11.0</plexus-archiver.version>
100-
<pluginTestingVersion>3.4.0</pluginTestingVersion>
100+
<pluginTestingVersion>3.5.0</pluginTestingVersion>
101101

102102
<!-- strict check by dependency:analyze-only -->
103103
<enforce.dependency.declarations>true</enforce.dependency.declarations>
@@ -179,12 +179,6 @@ under the License.
179179
<artifactId>commons-lang3</artifactId>
180180
<version>3.20.0</version>
181181
</dependency>
182-
<dependency>
183-
<groupId>commons-io</groupId>
184-
<artifactId>commons-io</artifactId>
185-
<version>2.21.0</version>
186-
<scope>test</scope>
187-
</dependency>
188182
<dependency>
189183
<groupId>org.codehaus.plexus</groupId>
190184
<artifactId>plexus-utils</artifactId>
@@ -327,18 +321,6 @@ under the License.
327321
<version>2.0.1</version>
328322
<scope>test</scope>
329323
</dependency>
330-
<dependency>
331-
<!-- support for JUnit 4 -->
332-
<groupId>org.junit.vintage</groupId>
333-
<artifactId>junit-vintage-engine</artifactId>
334-
<scope>test</scope>
335-
</dependency>
336-
<dependency>
337-
<groupId>junit</groupId>
338-
<artifactId>junit</artifactId>
339-
<version>4.13.2</version>
340-
<scope>test</scope>
341-
</dependency>
342324
<dependency>
343325
<groupId>org.apache.maven.plugin-testing</groupId>
344326
<artifactId>maven-plugin-testing-harness</artifactId>

src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,43 @@
1818
*/
1919
package org.apache.maven.plugins.dependency;
2020

21-
import java.io.File;
2221
import java.util.Set;
2322

23+
import org.apache.maven.api.plugin.testing.InjectMojo;
24+
import org.apache.maven.api.plugin.testing.MojoParameter;
25+
import org.apache.maven.api.plugin.testing.MojoTest;
2426
import org.apache.maven.artifact.Artifact;
25-
import org.apache.maven.execution.MavenSession;
2627
import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
27-
import org.apache.maven.plugins.dependency.resolvers.ResolveDependenciesMojo;
28-
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
28+
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
2929
import org.apache.maven.plugins.dependency.utils.DependencySilentLog;
3030
import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
3131
import org.apache.maven.project.MavenProject;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
3234

33-
public class TestCollectMojo extends AbstractDependencyMojoTestCase {
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertFalse;
37+
import static org.junit.jupiter.api.Assertions.assertNotNull;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
3439

35-
@Override
36-
protected String getTestDirectoryName() {
37-
return "markers";
38-
}
39-
40-
@Override
41-
protected boolean shouldCreateFiles() {
42-
return false;
43-
}
44-
45-
@Override
46-
protected void setUp() throws Exception {
47-
// required for mojo lookups to work
48-
super.setUp();
40+
@MojoTest
41+
class TestCollectMojo {
4942

50-
MavenProject project = new DependencyProjectStub();
51-
getContainer().addComponent(project, MavenProject.class.getName());
43+
private DependencyArtifactStubFactory stubFactory;
5244

53-
MavenSession session = newMavenSession(project);
54-
getContainer().addComponent(session, MavenSession.class.getName());
45+
@BeforeEach
46+
void setUp() throws Exception {
47+
stubFactory = new DependencyArtifactStubFactory(null, false);
5548
}
5649

5750
/**
5851
* tests the proper discovery and configuration of the mojo
5952
*
6053
* @throws Exception if a problem occurs
6154
*/
62-
public void testCollectTestEnvironment() throws Exception {
63-
File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
64-
CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
55+
@Test
56+
@InjectMojo(goal = "collect")
57+
void testCollectTestEnvironment(CollectDependenciesMojo mojo) throws Exception {
6558

6659
assertNotNull(mojo);
6760
assertNotNull(mojo.getProject());
@@ -85,10 +78,10 @@ public void testCollectTestEnvironment() throws Exception {
8578
*
8679
* @throws Exception if a problem occurs
8780
*/
88-
public void testCollectTestEnvironmentExcludeTransitive() throws Exception {
89-
File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
90-
CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
91-
81+
@Test
82+
@InjectMojo(goal = "collect")
83+
@MojoParameter(name = "excludeTransitive", value = "true")
84+
void testCollectTestEnvironmentExcludeTransitive(CollectDependenciesMojo mojo) throws Exception {
9285
assertNotNull(mojo);
9386
assertNotNull(mojo.getProject());
9487
MavenProject project = mojo.getProject();
@@ -100,18 +93,15 @@ public void testCollectTestEnvironmentExcludeTransitive() throws Exception {
10093
project.setArtifacts(artifacts);
10194
project.setDependencyArtifacts(directArtifacts);
10295

103-
setVariableValueToObject(mojo, "excludeTransitive", Boolean.TRUE);
104-
10596
mojo.execute();
10697
DependencyStatusSets results = mojo.getResults();
10798
assertNotNull(results);
10899
assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
109100
}
110101

111-
public void testSilent() throws Exception {
112-
File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml");
113-
ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom);
114-
102+
@Test
103+
@InjectMojo(goal = "collect")
104+
void testSilent(CollectDependenciesMojo mojo) throws Exception {
115105
assertFalse(mojo.getLog() instanceof DependencySilentLog);
116106

117107
mojo.setSilent(true);

0 commit comments

Comments
 (0)