From 7ce149222a9e5671feddbcf4853bd8eed795f0f2 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Mon, 20 Oct 2025 08:48:09 +0000 Subject: [PATCH 1/2] Migrate JUnit3 based Tests to JUnit 5 (#1541) * chore: migration from junit3 to junit5 Signed-off-by: Sandra Parsick * chore: remove unused code Signed-off-by: Sandra Parsick --------- Signed-off-by: Sandra Parsick --- .../AbstractDependencyMojoTest.java | 70 ------------------- .../dependency/analyze/TestAnalyzeDepMgt.java | 18 +++-- .../markers/TestSourcesMarkerFileHandler.java | 27 +++++-- 3 files changed, 36 insertions(+), 79 deletions(-) delete mode 100644 src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTest.java diff --git a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTest.java deleted file mode 100644 index 6d45e86e1..000000000 --- a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.plugins.dependency; - -import java.util.ArrayList; - -import junit.framework.TestCase; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuildingRequest; -import org.sonatype.plexus.build.incremental.BuildContext; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AbstractDependencyMojoTest extends TestCase { - private MavenSession session = mock(MavenSession.class); - - private ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); - - private ArrayList artifactRepos = new ArrayList<>(); - - private ArrayList pluginRepos = new ArrayList<>(); - - static class ConcreteDependencyMojo extends AbstractDependencyMojo { - - protected ConcreteDependencyMojo(MavenSession session, BuildContext buildContext, MavenProject project) { - super(session, buildContext, project); - } - - @Override - protected void doExecute() {} - } - - @Override - protected void setUp() throws Exception { - pluginRepos.add(newRepositoryWithId("pr-central")); - pluginRepos.add(newRepositoryWithId("pr-plugins")); - - artifactRepos.add(newRepositoryWithId("ar-central")); - artifactRepos.add(newRepositoryWithId("ar-snapshots")); - artifactRepos.add(newRepositoryWithId("ar-staging")); - - when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT); - when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); - } - - private static ArtifactRepository newRepositoryWithId(String id) { - ArtifactRepository repo = mock(ArtifactRepository.class); - when(repo.getId()).thenReturn(id); - return repo; - } -} diff --git a/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java b/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java index 32c0919c6..9f4a71fac 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java +++ b/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Set; -import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -36,10 +35,16 @@ import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory; import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -public class TestAnalyzeDepMgt extends TestCase { +public class TestAnalyzeDepMgt { AnalyzeDepMgt mojo; @@ -51,8 +56,8 @@ public class TestAnalyzeDepMgt extends TestCase { DependencyManagement depMgt; - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { MavenProject project = new DependencyProjectStub(); mojo = new AnalyzeDepMgt(project); @@ -86,6 +91,7 @@ protected void setUp() throws Exception { project.setDependencyArtifacts(directArtifacts); } + @Test public void testGetManagementKey() throws IOException { Dependency dep = new Dependency(); dep.setArtifactId("artifact"); @@ -145,6 +151,7 @@ public void testGetManagementKey() throws IOException { assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact)); } + @Test public void testAddExclusions() { assertEquals(0, mojo.addExclusions(null).size()); @@ -158,6 +165,7 @@ public void testAddExclusions() { assertSame(ex, map.get(mojo.getExclusionKey(ex))); } + @Test public void testGetExclusionErrors() { List list = new ArrayList<>(); list.add(ex); @@ -172,6 +180,7 @@ public void testGetExclusionErrors() { assertEquals(mojo.getExclusionKey(ex), mojo.getExclusionKey(l.get(0))); } + @Test public void testGetMismatch() throws IOException { Map depMgtMap = new HashMap<>(); @@ -186,6 +195,7 @@ public void testGetMismatch() throws IOException { assertSame(exclusion, results.get(stubFactory.getReleaseArtifact())); } + @Test public void testMojo() throws IOException, MojoExecutionException, MojoFailureException { mojo.setIgnoreDirect(false); // test with nothing in depMgt diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestSourcesMarkerFileHandler.java b/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestSourcesMarkerFileHandler.java index 0a498e3a4..64eab4066 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestSourcesMarkerFileHandler.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestSourcesMarkerFileHandler.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Random; -import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -34,19 +33,26 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.testing.SilentLog; import org.apache.maven.plugins.dependency.testUtils.stubs.StubSourcesFileMarkerHandler; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author brianf */ -public class TestSourcesMarkerFileHandler extends TestCase { +public class TestSourcesMarkerFileHandler { List artifacts = new ArrayList<>(); Log log = new SilentLog(); File outputFolder; - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + public void setUp() throws Exception { ArtifactHandler ah = new DefaultArtifactHandler(); VersionRange vr = VersionRange.createFromVersion("1.1"); @@ -66,10 +72,12 @@ protected void setUp() throws Exception { assertFalse(outputFolder.exists()); } - protected void tearDown() { + @AfterEach + public void tearDown() { outputFolder.delete(); } + @Test public void testSetMarkerResolved() throws MojoExecutionException { DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, true); assertFalse(handler.isMarkerSet()); @@ -88,6 +96,7 @@ public void testSetMarkerResolved() throws MojoExecutionException { assertFalse(outputFolder.exists()); } + @Test public void testSetMarkerUnresolved() throws MojoExecutionException { DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, false); assertFalse(handler.isMarkerSet()); @@ -106,6 +115,7 @@ public void testSetMarkerUnresolved() throws MojoExecutionException { assertFalse(outputFolder.exists()); } + @Test public void testBothMarkers() throws MojoExecutionException { DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(1), this.outputFolder, true); DefaultFileMarkerHandler handler2 = new SourcesFileMarkerHandler(artifacts.get(1), this.outputFolder, false); @@ -121,6 +131,7 @@ public void testBothMarkers() throws MojoExecutionException { assertFalse(outputFolder.exists()); } + @Test public void testMarkerFile() throws MojoExecutionException, IOException { DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, true); DefaultFileMarkerHandler handler2 = new SourcesFileMarkerHandler(artifacts.get(0), this.outputFolder, false); @@ -176,10 +187,12 @@ public void testMarkerFile() throws MojoExecutionException, IOException { assertFalse(outputFolder.exists()); } + @Test public void testMarkerTimeStampResolved() throws MojoExecutionException, IOException, InterruptedException { doTestMarkerTimeStamp(true); } + @Test public void testMarkerTimeStampUnResolved() throws MojoExecutionException, IOException, InterruptedException { doTestMarkerTimeStamp(false); } @@ -220,6 +233,7 @@ public void doTestMarkerTimeStamp(boolean resolved) assertFalse(resolvedHandler.isMarkerSet()); } + @Test public void testMarkerFileException() { // this stub wraps the file with an object to throw exceptions StubSourcesFileMarkerHandler handler = @@ -231,6 +245,7 @@ public void testMarkerFileException() { } } + @Test public void testMarkerFileResolvedSetter() { SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(null, null, true); assertTrue(handler.isResolved()); @@ -238,6 +253,7 @@ public void testMarkerFileResolvedSetter() { assertFalse(handler.isResolved()); } + @Test public void testNullParent() throws MojoExecutionException { // the parent isn't set so this will create the marker in the local // folder. We must clear the @@ -250,6 +266,7 @@ public void testNullParent() throws MojoExecutionException { assertFalse(handler.isMarkerSet()); } + @Test public void testNullParentResolved() throws MojoExecutionException { // the parent isn't set so this will create the marker in the local // folder. We must clear the From 3603ecc1f3e6291fb66fe174f3131c4031e698d8 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 20 Oct 2025 15:26:41 +0000 Subject: [PATCH 2/2] Focus on most recent version (#1537) Removed outdated notes about plugin version and redundant copy-pasta about contributing. --- src/site/apt/examples/tree-mojo.apt.vm | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/site/apt/examples/tree-mojo.apt.vm b/src/site/apt/examples/tree-mojo.apt.vm index 5c5a6ba32..2e3f847f6 100644 --- a/src/site/apt/examples/tree-mojo.apt.vm +++ b/src/site/apt/examples/tree-mojo.apt.vm @@ -283,10 +283,6 @@ mvn dependency:tree -DoutputType=tgf -DoutputFile=dependency-tree.tgf * Notes - * <>: The <<>>, <<>>, <<>>, and <<>> output formats are - available starting with Maven Dependency Plugin version 3.7.0. Always use the latest version - (3.8.1 as of June 2025) for the most stable experience. - * <>: * <>: Parse with any JSON-compatible tool (e.g., Python's <<>> module, JavaScript's <<>>). @@ -297,8 +293,3 @@ mvn dependency:tree -DoutputType=tgf -DoutputFile=dependency-tree.tgf * <>: Use tools supporting TGF or convert to DOT/GraphML for visualization. - * <>: If you encounter issues or want to improve this documentation, contribute to - the Maven Dependency Plugin repository at - {{{https://github.com/apache/maven-dependency-plugin}https://github.com/apache/maven-dependency-plugin}}. - See the - {{{https://maven.apache.org/guides/development/guide-helping.html}guide to helping with Maven}}.