From 6d28b4629977b08e32dc090bb676f046903ef23e Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 2 Nov 2025 12:44:15 +0000 Subject: [PATCH] Migrate JUnit 4 `TestCase` to JUnit Jupiter Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.testing.junit5.MigrateJUnitTestCase?organizationId=QUxML09wZW4gU291cmNlL05ldGZsaXggKyBTcHJpbmcgKyBBcGFjaGUvQXBhY2hlL0FwYWNoZSBNYXZlbg%3D%3D Co-authored-by: Moderne --- .../AbstractDependencyMojoTestCase.java | 13 ++-- .../plugins/dependency/TestCollectMojo.java | 14 +++- .../maven/plugins/dependency/TestGetMojo.java | 14 +++- .../dependency/TestListClassesMojo.java | 23 +++++-- .../dependency/TestPropertiesMojo.java | 10 ++- .../maven/plugins/dependency/TestSkip.java | 29 +++++++- .../analyze/TestAnalyzeDuplicateMojo.java | 6 ++ .../exclusion/AnalyzeExclusionsMojoTest.java | 14 +++- .../fromConfiguration/TestArtifactItem.java | 10 ++- .../fromConfiguration/TestCopyMojo.java | 43 +++++++++++- .../TestIncludeExcludeUnpackMojo.java | 22 +++++- .../fromConfiguration/TestUnpackMojo.java | 35 ++++++++-- .../TestBuildClasspathMojo.java | 19 +++-- .../TestCopyDependenciesMojo.java | 69 +++++++++++++++---- .../TestCopyDependenciesMojo2.java | 27 ++++++-- ...tIncludeExcludeUnpackDependenciesMojo.java | 16 ++++- .../TestRenderDependenciesMojo.java | 8 ++- .../TestUnpackDependenciesMojo.java | 38 +++++++++- .../TestUnpackDependenciesMojo2.java | 16 ++++- ...ludeReactorProjectsArtifactFilterTest.java | 5 ++ ...deReactorProjectsDependencyFilterTest.java | 5 ++ .../resolvers/GoOfflineMojoTest.java | 19 ++++- .../ResolveDependenciesMojoTest.java | 12 +++- .../dependency/resolvers/TestResolveMojo.java | 13 +++- .../plugins/dependency/tree/TestTreeMojo.java | 26 +++++-- .../utils/TestDependencyStatusSets.java | 8 ++- .../markers/TestUnpackMarkerFileHandler.java | 6 ++ .../TestClassifierTypeTranslator.java | 15 +++- 28 files changed, 452 insertions(+), 83 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java index 7e1006770..33385c720 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java +++ b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java @@ -35,8 +35,12 @@ import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.sonatype.plexus.build.incremental.DefaultBuildContext; +import static org.junit.jupiter.api.Assertions.assertFalse; + public abstract class AbstractDependencyMojoTestCase extends AbstractMojoTestCase { protected File testDir; @@ -51,7 +55,8 @@ public abstract class AbstractDependencyMojoTestCase extends AbstractMojoTestCas * * @throws Exception if setup fails */ - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // Required for mojo lookups to work super.setUp(); @@ -94,11 +99,11 @@ protected boolean shouldUseFlattenedPath() { * * @throws Exception if cleanup fails */ - @Override - protected void tearDown() throws Exception { + @AfterEach + public void tearDown() throws Exception { if (testDir != null) { FileUtils.deleteDirectory(testDir); - assertFalse("Test directory should not exist after cleanup", testDir.exists()); + assertFalse(testDir.exists(), "Test directory should not exist after cleanup"); } super.tearDown(); } diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java b/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java index f93ee2cef..dcab9dbf1 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java @@ -29,6 +29,13 @@ import org.apache.maven.plugins.dependency.utils.DependencySilentLog; import org.apache.maven.plugins.dependency.utils.DependencyStatusSets; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestCollectMojo extends AbstractDependencyMojoTestCase { @@ -42,8 +49,8 @@ protected boolean shouldCreateFiles() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -59,6 +66,7 @@ protected void setUp() throws Exception { * * @throws Exception if a problem occurs */ + @Test public void testCollectTestEnvironment() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml"); CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom); @@ -85,6 +93,7 @@ public void testCollectTestEnvironment() throws Exception { * * @throws Exception if a problem occurs */ + @Test public void testCollectTestEnvironmentExcludeTransitive() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml"); CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom); @@ -108,6 +117,7 @@ public void testCollectTestEnvironmentExcludeTransitive() throws Exception { assertEquals(directArtifacts.size(), results.getResolvedDependencies().size()); } + @Test public void testSilent() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml"); ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom); diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java b/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java index ae793392d..a25421bfb 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java @@ -43,6 +43,12 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.util.security.Constraint; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class TestGetMojo extends AbstractDependencyMojoTestCase { private GetMojo mojo; @@ -57,8 +63,8 @@ protected boolean shouldCreateFiles() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); MavenProject project = new DependencyProjectStub(); @@ -91,6 +97,7 @@ protected void setUp() throws Exception { * * @throws Exception in case of errors */ + @Test public void testTransitive() throws Exception { // Set properties, transitive = default value = true setVariableValueToObject(mojo, "transitive", Boolean.FALSE); @@ -111,6 +118,7 @@ public void testTransitive() throws Exception { * * @throws Exception in case of errors */ + @Test public void testRemoteRepositories() throws Exception { setVariableValueToObject( mojo, @@ -129,6 +137,7 @@ public void testRemoteRepositories() throws Exception { * * @throws Exception in case of errors */ + @Test public void testRemoteRepositoriesAuthentication() throws Exception { org.eclipse.jetty.server.Server server = createServer(); try { @@ -156,6 +165,7 @@ public void testRemoteRepositoriesAuthentication() throws Exception { * * @throws Exception in case of errors */ + @Test public void testParseRepository() throws Exception { ArtifactRepositoryPolicy policy = null; ArtifactRepository repo = diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestListClassesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/TestListClassesMojo.java index 1569b9173..05eccd596 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/TestListClassesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/TestListClassesMojo.java @@ -31,10 +31,15 @@ import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.project.MavenProject; import org.eclipse.aether.RepositorySystem; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestListClassesMojo extends AbstractDependencyMojoTestCase { private ListClassesMojo mojo; @@ -48,8 +53,8 @@ protected boolean shouldCreateFiles() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { super.setUp(); MavenProject project = new DependencyProjectStub(); @@ -73,6 +78,7 @@ protected void setUp() throws Exception { installLocalRepository(session.getRepositorySession()); } + @Test public void testListClassesNotTransitive() throws Exception { Path path = Paths.get("src/test/resources/unit/list-test/testListClassesNotTransitive.txt"); List expectedLogArgs = Files.readAllLines(path); @@ -94,9 +100,10 @@ public void testListClassesNotTransitive() throws Exception { mojo.execute(); Mockito.verify(log, Mockito.times(expectedLogArgs.size())).info(infoArgsCaptor.capture()); - Assert.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); + Assertions.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); } + @Test public void testListClassesNotTransitiveByGAV() throws Exception { Path path = Paths.get("src/test/resources/unit/list-test/testListClassesNotTransitive.txt"); List expectedLogArgs = Files.readAllLines(path); @@ -122,9 +129,10 @@ public void testListClassesNotTransitiveByGAV() throws Exception { mojo.execute(); Mockito.verify(log, Mockito.times(expectedLogArgs.size())).info(infoArgsCaptor.capture()); - Assert.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); + Assertions.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); } + @Test public void testListClassesTransitive() throws Exception { Path path = Paths.get("src/test/resources/unit/list-test/testListClassesTransitive.txt"); List expectedLogArgs = Files.readAllLines(path); @@ -147,9 +155,10 @@ public void testListClassesTransitive() throws Exception { mojo.execute(); Mockito.verify(log, Mockito.times(expectedLogArgs.size())).info(infoArgsCaptor.capture()); - Assert.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); + Assertions.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); } + @Test public void testListClassesTransitiveByGAV() throws Exception { Path path = Paths.get("src/test/resources/unit/list-test/testListClassesTransitive.txt"); List expectedLogArgs = Files.readAllLines(path); @@ -173,6 +182,6 @@ public void testListClassesTransitiveByGAV() throws Exception { mojo.execute(); Mockito.verify(log, Mockito.times(expectedLogArgs.size())).info(infoArgsCaptor.capture()); - Assert.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); + Assertions.assertEquals(expectedLogArgs, infoArgsCaptor.getAllValues()); } } diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java index 2e3db085f..b19047565 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java @@ -25,6 +25,11 @@ import org.apache.maven.execution.MavenSession; 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.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestPropertiesMojo extends AbstractDependencyMojoTestCase { @@ -38,8 +43,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -55,6 +60,7 @@ protected void setUp() throws Exception { * * @throws Exception in case of errors */ + @Test public void testSetProperties() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/properties-test/plugin-config.xml"); PropertiesMojo mojo = (PropertiesMojo) lookupMojo("properties", testPom); diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java index 1fbcacb08..410b581cc 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java +++ b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java @@ -29,16 +29,20 @@ import org.apache.maven.plugin.logging.Log; 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 org.mockito.ArgumentCaptor; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; public class TestSkip extends AbstractDependencyMojoTestCase { - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { super.setUp(); MavenProject project = new DependencyProjectStub(); getContainer().addComponent(project, MavenProject.class.getName()); @@ -47,78 +51,97 @@ protected void setUp() throws Exception { getContainer().addComponent(session, MavenSession.class.getName()); } + @Test public void testSkipAnalyze() throws Exception { doTest("analyze"); } + @Test public void testSkipAnalyzeDepMgt() throws Exception { doTest("analyze-dep-mgt"); } + @Test public void testSkipAnalyzeOnly() throws Exception { doTest("analyze-only"); } + @Test public void testSkipAnalyzeReport() throws Exception { doSpecialTest("analyze-report", true); } + @Test public void testSkipAnalyzeDuplicate() throws Exception { doTest("analyze-duplicate"); } + @Test public void testSkipBuildClasspath() throws Exception { doTest("build-classpath"); } + @Test public void testSkipCopy() throws Exception { doTest("copy"); } + @Test public void testSkipCopyDependencies() throws Exception { doTest("copy-dependencies"); } + @Test public void testSkipGet() throws Exception { doSpecialTest("get"); } + @Test public void testSkipGoOffline() throws Exception { doTest("go-offline"); } + @Test public void testSkipList() throws Exception { doTest("list"); } + @Test public void testSkipProperties() throws Exception { doTest("properties"); } + @Test public void testSkipPurgeLocalRepository() throws Exception { doSpecialTest("purge-local-repository"); } + @Test public void testSkipResolve() throws Exception { doTest("resolve"); } + @Test public void testSkipResolvePlugins() throws Exception { doTest("resolve-plugins"); } + @Test public void testSkipSources() throws Exception { doTest("sources"); } + @Test public void testSkipTree() throws Exception { doTest("tree"); } + @Test public void testSkipUnpack() throws Exception { doTest("unpack"); } + @Test public void testSkipUnpackDependencies() throws Exception { doTest("unpack-dependencies"); } @@ -142,7 +165,7 @@ private void doConfigTest(String mojoName, String configFile) throws Exception { private void doConfigTest(String mojoName, String configFile, boolean addMojoExecution) throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/skip-test/" + configFile); Mojo mojo = lookupMojo(mojoName, testPom); - assertNotNull("Mojo not found.", mojo); + assertNotNull(mojo, "Mojo not found."); if (addMojoExecution) { setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution(mojoName)); diff --git a/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDuplicateMojo.java b/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDuplicateMojo.java index b0b758092..9671fb6b9 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDuplicateMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDuplicateMojo.java @@ -28,12 +28,17 @@ import org.apache.maven.plugins.dependency.testUtils.stubs.DuplicateDependencies2ProjectStub; import org.apache.maven.plugins.dependency.testUtils.stubs.DuplicateDependenciesProjectStub; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Vincent Siveton * @version $Id$ */ public class TestAnalyzeDuplicateMojo extends AbstractDependencyMojoTestCase { + @Test public void testDuplicate() throws Exception { MavenProject project = new DuplicateDependenciesProjectStub(); getContainer().addComponent(project, MavenProject.class.getName()); @@ -53,6 +58,7 @@ public void testDuplicate() throws Exception { assertTrue(log.getContent().contains("junit:junit:jar")); } + @Test public void testDuplicate2() throws Exception { MavenProject project = new DuplicateDependencies2ProjectStub(); getContainer().addComponent(project, MavenProject.class.getName()); diff --git a/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java index d0da7947a..7d348075d 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java @@ -40,10 +40,13 @@ import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -73,8 +76,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -100,6 +103,7 @@ protected void setUp() throws Exception { mojo.setLog(testLog); } + @Test public void testShallThrowExceptionWhenFailOnWarning() throws Exception { List dependencies = new ArrayList<>(); Dependency withInvalidExclusion = dependency("a", "b"); @@ -117,6 +121,7 @@ public void testShallThrowExceptionWhenFailOnWarning() throws Exception { assertThat(testLog.getContent()).startsWith("[error]"); } + @Test public void testShallLogWarningWhenFailOnWarningIsFalse() throws Exception { List dependencies = new ArrayList<>(); Dependency withInvalidExclusion = dependency("a", "b"); @@ -132,6 +137,7 @@ public void testShallLogWarningWhenFailOnWarningIsFalse() throws Exception { assertThat(testLog.getContent()).startsWith("[warn]"); } + @Test public void testShallExitWithoutAnalyzeWhenNoDependencyHasExclusion() throws Exception { List dependencies = new ArrayList<>(); dependencies.add(dependency("a", "c")); @@ -140,6 +146,7 @@ public void testShallExitWithoutAnalyzeWhenNoDependencyHasExclusion() throws Exc assertThat(testLog.getContent()).startsWith("[debug] No dependencies defined with exclusions - exiting"); } + @Test public void testShallNotReportInvalidExclusionForWildcardGroupIdAndArtifactId() throws Exception { Dependency dependencyWithWildcardExclusion = dependency("a", "b"); dependencyWithWildcardExclusion.addExclusion(exclusion("*", "*")); @@ -156,6 +163,7 @@ public void testShallNotReportInvalidExclusionForWildcardGroupIdAndArtifactId() assertThat(testLog.getContent()).doesNotContain("[warn] a:b:", "[warn] - *:*"); } + @Test public void testCanResolveMultipleArtifactsWithEqualGroupIdAndArtifactId() throws Exception { Dependency dependency1 = dependency("a", "b"); Dependency dependency2 = dependency("a", "b", "compile", "native"); @@ -169,6 +177,7 @@ public void testCanResolveMultipleArtifactsWithEqualGroupIdAndArtifactId() throw assertThatCode(() -> mojo.execute()).doesNotThrowAnyException(); } + @Test public void testShallNotLogWhenExclusionIsValid() throws Exception { List dependencies = new ArrayList<>(); Dependency dependency = dependency("a", "b"); @@ -187,6 +196,7 @@ public void testShallNotLogWhenExclusionIsValid() throws Exception { assertThatCode(() -> mojo.execute()).doesNotThrowAnyException(); } + @Test public void testThatLogContainProjectName() throws Exception { List dependencies = new ArrayList<>(); Dependency withInvalidExclusion = dependency("a", "b"); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestArtifactItem.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestArtifactItem.java index 63fefb1de..8c6f5dae8 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestArtifactItem.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestArtifactItem.java @@ -22,6 +22,10 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestArtifactItem extends AbstractDependencyMojoTestCase { @@ -35,12 +39,13 @@ protected boolean shouldCreateFiles() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); } + @Test public void testArtifactItemConstructor() throws IOException { Artifact artifact = stubFactory.createArtifact("g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", "one"); @@ -54,6 +59,7 @@ public void testArtifactItemConstructor() throws IOException { assertEquals(item.getType(), artifact.getType()); } + @Test public void testArtifactItemDefaultType() { ArtifactItem item = new ArtifactItem(); // check type default diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java index a619d7750..d12a71383 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java @@ -33,6 +33,15 @@ import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; import org.apache.maven.plugins.dependency.utils.DependencyUtil; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestCopyMojo extends AbstractDependencyMojoTestCase { private CopyMojo mojo; @@ -52,8 +61,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -80,6 +89,7 @@ private ArtifactItem getSingleArtifactItem(boolean removeVersion, boolean useBas return list.get(0); } + @Test public void testSetArtifactWithoutPackaging() throws Exception { mojo.setArtifact("a:b:c"); ArtifactItem item = mojo.getArtifactItems().get(0); @@ -90,6 +100,7 @@ public void testSetArtifactWithoutPackaging() throws Exception { assertNull(item.getClassifier()); } + @Test public void testSetArtifactWithoutClassifier() throws Exception { mojo.setArtifact("a:b:c:d"); ArtifactItem item = mojo.getArtifactItems().get(0); @@ -100,6 +111,7 @@ public void testSetArtifactWithoutClassifier() throws Exception { assertNull(item.getClassifier()); } + @Test public void testSetArtifact() throws Exception { mojo.setArtifact("a:b:c:d:e"); ArtifactItem item = mojo.getArtifactItems().get(0); @@ -110,6 +122,7 @@ public void testSetArtifact() throws Exception { assertEquals("e", item.getClassifier()); } + @Test public void testGetArtifactItems() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -143,6 +156,7 @@ public void assertFileExists(ArtifactItem item, boolean exist) { assertEquals(exist, file.exists()); } + @Test public void testMojoDefaults() { CopyMojo theMojo = new CopyMojo(null, null, null, null, null, null); @@ -151,6 +165,7 @@ public void testMojoDefaults() { assertFalse(theMojo.isStripClassifier()); } + @Test public void testCopyFile() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -182,6 +197,7 @@ public void skipTestCopyFileWithBaseVersion() throws Exception { assertFilesExist(list, true); } + @Test public void testSkip() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -196,6 +212,7 @@ public void testSkip() throws Exception { } } + @Test public void testCopyFileNoOverwrite() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -210,6 +227,7 @@ public void testCopyFileNoOverwrite() throws Exception { assertFilesExist(list, true); } + @Test public void testCopyToLocation() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); ArtifactItem item = list.get(0); @@ -222,6 +240,7 @@ public void testCopyToLocation() throws Exception { assertFilesExist(list, true); } + @Test public void testCopyStripVersionSetInMojo() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -237,6 +256,7 @@ public void testCopyStripVersionSetInMojo() throws Exception { assertFilesExist(list, true); } + @Test public void testCopyStripClassifierSetInMojo() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -254,6 +274,7 @@ public void testCopyStripClassifierSetInMojo() throws Exception { assertFilesExist(list, true); } + @Test public void testNonClassifierStrip() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getReleaseAndSnapshotArtifacts()); mojo.setStripVersion(true); @@ -264,6 +285,7 @@ public void testNonClassifierStrip() throws Exception { assertFilesExist(list, true); } + @Test public void testNonClassifierNoStrip() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getReleaseAndSnapshotArtifacts()); @@ -274,6 +296,7 @@ public void testNonClassifierNoStrip() throws Exception { assertFilesExist(list, true); } + @Test public void testMissingVersionNotFound() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -316,6 +339,7 @@ public List getDependencyList(ArtifactItem item) { return list; } + @Test public void testMissingVersionFromDependencies() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -336,6 +360,7 @@ public void testMissingVersionFromDependencies() throws Exception { assertEquals("2.0-SNAPSHOT", item.getVersion()); } + @Test public void testMissingVersionFromDependenciesLooseMatch() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -365,6 +390,7 @@ public void testMissingVersionFromDependenciesLooseMatch() throws Exception { assertEquals("2.1", item.getVersion()); } + @Test public void testMissingVersionFromDependenciesWithClassifier() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -407,6 +433,7 @@ public List getDependencyMgtList(ArtifactItem item) { return list; } + @Test public void testMissingVersionFromDependencyMgt() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -438,6 +465,7 @@ public void testMissingVersionFromDependencyMgt() throws Exception { assertEquals("3.0-SNAPSHOT", item.getVersion()); } + @Test public void testMissingVersionFromDependencyMgtLooseMatch() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -476,6 +504,7 @@ public void testMissingVersionFromDependencyMgtLooseMatch() throws Exception { assertEquals("3.1", item.getVersion()); } + @Test public void testMissingVersionFromDependencyMgtWithClassifier() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -507,6 +536,7 @@ public void testMissingVersionFromDependencyMgtWithClassifier() throws Exception assertEquals("3.1", item.getVersion()); } + @Test public void testArtifactNotFound() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -528,6 +558,7 @@ public void testArtifactNotFound() throws Exception { } } + @Test public void testNoArtifactItems() { try { mojo.getProcessedArtifactItems(new ProcessArtifactItemsRequest(false, false, false, false)); @@ -537,6 +568,7 @@ public void testNoArtifactItems() { } } + @Test public void testCopyDontOverWriteReleases() throws Exception { stubFactory.setCreateFiles(true); Artifact release = stubFactory.getReleaseArtifact(); @@ -566,6 +598,7 @@ public void testCopyDontOverWriteReleases() throws Exception { assertEquals(time, copiedFile.lastModified()); } + @Test public void testCopyDontOverWriteSnapshots() throws Exception { stubFactory.setCreateFiles(true); Artifact artifact = stubFactory.getSnapshotArtifact(); @@ -595,6 +628,7 @@ public void testCopyDontOverWriteSnapshots() throws Exception { assertEquals(time, copiedFile.lastModified()); } + @Test public void testCopyOverWriteReleases() throws Exception { stubFactory.setCreateFiles(true); Artifact release = stubFactory.getReleaseArtifact(); @@ -622,6 +656,7 @@ public void testCopyOverWriteReleases() throws Exception { assertEquals(1000L, timeCopyNow); } + @Test public void testCopyOverWriteSnapshot() throws Exception { stubFactory.setCreateFiles(true); Artifact artifact = stubFactory.getSnapshotArtifact(); @@ -650,6 +685,7 @@ public void testCopyOverWriteSnapshot() throws Exception { assertEquals(1000L, timeCopyNow); } + @Test public void testCopyOverWriteIfNewer() throws Exception { stubFactory.setCreateFiles(true); Artifact artifact = stubFactory.getSnapshotArtifact(); @@ -677,6 +713,7 @@ public void testCopyOverWriteIfNewer() throws Exception { assertTrue(time < copiedFile.lastModified()); } + @Test public void testCopyFileWithOverideLocalRepo() throws Exception { final File localRepo = stubFactory.getWorkingDir(); @@ -690,7 +727,7 @@ public void testCopyFileWithOverideLocalRepo() throws Exception { stubFactory.setWorkingDir(execLocalRepo); createArtifactItemArtifacts(list); - assertFalse("default local repo should not exist", localRepo.exists()); + assertFalse(localRepo.exists(), "default local repo should not exist"); mojo.setLocalRepositoryDirectory(execLocalRepo); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java index f42e42aed..984e8d8e5 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java @@ -31,6 +31,13 @@ import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase { private static final String PACKED_FILE = "test.zip"; @@ -58,8 +65,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -116,6 +123,7 @@ private void assertUnpacked(boolean unpacked, String fileName) { * * @throws Exception in case of errors. */ + @Test public void testUnpackIncludesManyFiles() throws Exception { mojo.setIncludes("**/*1" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -130,6 +138,7 @@ public void testUnpackIncludesManyFiles() throws Exception { * * @throws Exception in case of errors. */ + @Test public void testUnpackIncludesSingleFile() throws Exception { mojo.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -144,6 +153,7 @@ public void testUnpackIncludesSingleFile() throws Exception { * * @throws Exception in case of errors. */ + @Test public void testUnpackIncludesAllFiles() throws Exception { mojo.setIncludes("**/*"); mojo.execute(); @@ -158,6 +168,7 @@ public void testUnpackIncludesAllFiles() throws Exception { * * @throws Exception in case of errors. */ + @Test public void testUnpackExcludesManyFiles() throws Exception { mojo.setExcludes("**/*1" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -172,6 +183,7 @@ public void testUnpackExcludesManyFiles() throws Exception { * * @throws Exception in case of errors. */ + @Test public void testUnpackExcludesSingleFile() throws Exception { mojo.setExcludes("**/test2" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -186,6 +198,7 @@ public void testUnpackExcludesSingleFile() throws Exception { * * @throws Exception in case of errors. */ + @Test public void testUnpackExcludesAllFiles() throws Exception { mojo.setExcludes("**/*"); mojo.execute(); @@ -195,6 +208,7 @@ public void testUnpackExcludesAllFiles() throws Exception { assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX); } + @Test public void testNoIncludeExcludes() throws Exception { mojo.execute(); assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX); @@ -203,6 +217,7 @@ public void testNoIncludeExcludes() throws Exception { assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX); } + @Test public void testIncludeArtifactItemOverride() throws Exception { Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null); ArtifactItem item = stubFactory.getArtifactItem(artifact); @@ -218,6 +233,7 @@ public void testIncludeArtifactItemOverride() throws Exception { assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX); } + @Test public void testExcludeArtifactItemOverride() throws Exception { Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null); ArtifactItem item = stubFactory.getArtifactItem(artifact); @@ -233,6 +249,7 @@ public void testExcludeArtifactItemOverride() throws Exception { assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX); } + @Test public void testIncludeArtifactItemMultipleMarker() throws Exception { List list = new ArrayList<>(); Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null); @@ -253,6 +270,7 @@ public void testIncludeArtifactItemMultipleMarker() throws Exception { assertMarkerFiles(mojo.getArtifactItems(), true); } + @Test public void testIncludeArtifactItemMultipleExecutions() throws Exception { List list = new ArrayList<>(); Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java index 4346ed946..80743c5b0 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java @@ -37,8 +37,14 @@ import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.manager.ArchiverManager; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestUnpackMojo extends AbstractDependencyMojoTestCase { @@ -59,8 +65,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -94,6 +100,7 @@ public ArtifactItem getSingleArtifactItem(boolean removeVersion) throws MojoExec return list.get(0); } + @Test public void testGetArtifactItems() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -131,6 +138,7 @@ public void assertMarkerFile(boolean val, ArtifactItem item) { } } + @Test public void testUnpackFile() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -141,6 +149,7 @@ public void testUnpackFile() throws Exception { assertMarkerFiles(list, true); } + @Test public void testSkip() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); @@ -152,6 +161,7 @@ public void testSkip() throws Exception { assertMarkerFiles(list, false); } + @Test public void testUnpackToLocation() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); ArtifactItem item = list.get(0); @@ -164,6 +174,7 @@ public void testUnpackToLocation() throws Exception { assertMarkerFiles(list, true); } + @Test public void testUnpackToLocationWhereLocationCannotBeCreatedThrowsException() throws Exception { List list = stubFactory.getArtifactItems(stubFactory.getClassifiedArtifacts()); ArtifactItem item = list.get(0); @@ -193,6 +204,7 @@ public boolean exists() { } } + @Test public void testMissingVersionNotFound() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -235,6 +247,7 @@ public List getDependencyList(ArtifactItem item) { return list; } + @Test public void testMissingVersionFromDependencies() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -255,6 +268,7 @@ public void testMissingVersionFromDependencies() throws Exception { assertEquals("2.0-SNAPSHOT", item.getVersion()); } + @Test public void testMissingVersionFromDependenciesWithClassifier() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -297,6 +311,7 @@ public List getDependencyMgtList(ArtifactItem item) { return list; } + @Test public void testMissingVersionFromDependencyMgt() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -327,6 +342,7 @@ public void testMissingVersionFromDependencyMgt() throws Exception { assertEquals("3.0-SNAPSHOT", item.getVersion()); } + @Test public void testMissingVersionFromDependencyMgtWithClassifier() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -369,6 +385,7 @@ public void testMissingVersionFromDependencyMgtWithClassifier() throws Exception assertEquals("3.1", item.getVersion()); } + @Test public void testArtifactNotFound() throws Exception { ArtifactItem item = new ArtifactItem(); @@ -390,6 +407,7 @@ public void testArtifactNotFound() throws Exception { } } + @Test public void testNoArtifactItems() { try { mojo.getProcessedArtifactItems(false); @@ -399,6 +417,7 @@ public void testNoArtifactItems() { } } + @Test public void testUnpackDontOverWriteReleases() throws Exception { stubFactory.setCreateFiles(true); Artifact release = stubFactory.getReleaseArtifact(); @@ -417,6 +436,7 @@ public void testUnpackDontOverWriteReleases() throws Exception { assertUnpacked(item, false); } + @Test public void testUnpackDontOverWriteSnapshots() throws Exception { stubFactory.setCreateFiles(true); Artifact artifact = stubFactory.getSnapshotArtifact(); @@ -435,6 +455,7 @@ public void testUnpackDontOverWriteSnapshots() throws Exception { assertUnpacked(item, false); } + @Test public void testUnpackOverWriteReleases() throws Exception { stubFactory.setCreateFiles(true); Artifact release = stubFactory.getReleaseArtifact(); @@ -453,6 +474,7 @@ public void testUnpackOverWriteReleases() throws Exception { assertUnpacked(item, true); } + @Test public void testUnpackOverWriteSnapshot() throws Exception { stubFactory.setCreateFiles(true); Artifact artifact = stubFactory.getSnapshotArtifact(); @@ -478,6 +500,7 @@ public void testUnpackOverWriteSnapshot() throws Exception { * https://bugs.openjdk.java.net/browse/JDK-8177809 * */ + @Test public void testUnpackOverWriteIfNewer() throws Exception { final long now = System.currentTimeMillis(); @@ -516,10 +539,10 @@ public void testUnpackOverWriteIfNewer() throws Exception { Files.getLastModifiedTime(unpackedFile.toPath()).toMillis(); assertNotEquals( - "unpackedFile '" + unpackedFile + "' lastModified() == " + markerLastModifiedMillis - + ": should be different", markerLastModifiedMillis, - unpackedFileLastModifiedMillis); + unpackedFileLastModifiedMillis, + "unpackedFile '" + unpackedFile + "' lastModified() == " + markerLastModifiedMillis + + ": should be different"); } public void assertUnpacked(ArtifactItem item, boolean overWrite) throws Exception { diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestBuildClasspathMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestBuildClasspathMojo.java index 86856c633..2b98a5695 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestBuildClasspathMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestBuildClasspathMojo.java @@ -28,6 +28,15 @@ import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; import org.apache.maven.plugins.dependency.utils.DependencyUtil; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestBuildClasspathMojo extends AbstractDependencyMojoTestCase { @@ -43,8 +52,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -64,6 +73,7 @@ protected void setUp() throws Exception { /** * Tests the proper discovery and configuration of the mojo. */ + @Test public void testEnvironment() throws Exception { MavenProject project = mojo.getProject(); @@ -117,6 +127,7 @@ public void testEnvironment() throws Exception { assertNotNull(propertyValue); } + @Test public void testPath() throws Exception { LegacySupport legacySupport = lookup(LegacySupport.class); @@ -146,9 +157,9 @@ public void testPath() throws Exception { mojo.setPrependGroupId(true); mojo.appendArtifactPath(artifact, sb); assertEquals( - "If prefix is null, prependGroupId has no impact ", "%M2_REPO%" + File.separator + DependencyUtil.getFormattedFileName(artifact, false, false), - sb.toString()); + sb.toString(), + "If prefix is null, prependGroupId has no impact "); mojo.setLocalRepoProperty(""); mojo.setPrefix("prefix"); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java index bd5043bd8..e6909868d 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java @@ -38,6 +38,14 @@ import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler; import org.apache.maven.project.MavenProject; import org.eclipse.aether.RepositorySystem; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestCopyDependenciesMojo extends AbstractDependencyMojoTestCase { @@ -58,8 +66,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -100,6 +108,7 @@ public void assertNoMarkerFile(Artifact artifact) throws MojoExecutionException assertFalse(handle.isMarkerSet()); } + @Test public void testCopyArtifactFile() throws Exception { final Artifact srcArtifact = new ArtifactStub(); srcArtifact.setGroupId("org.apache.maven.plugins"); @@ -121,41 +130,42 @@ public void testCopyArtifactFile() throws Exception { * * @throws Exception if an error occurs during the test */ + @Test public void testCopySignatureFiles() throws Exception { // Enable the copySignatures parameter mojo.copySignatures = true; if (!mojo.outputDirectory.exists()) { - assertTrue("Failed to create output directory", mojo.outputDirectory.mkdirs()); + assertTrue(mojo.outputDirectory.mkdirs(), "Failed to create output directory"); } File sourceDirectory = new File(System.getProperty("java.io.tmpdir"), "test-source-" + System.currentTimeMillis()); if (!sourceDirectory.exists()) { - assertTrue("Failed to create source directory", sourceDirectory.mkdirs()); + assertTrue(sourceDirectory.mkdirs(), "Failed to create source directory"); } File artifactFile = new File(sourceDirectory, "maven-dependency-plugin-1.0.jar"); if (!artifactFile.getParentFile().exists()) { assertTrue( - "Failed to create parent directory", - artifactFile.getParentFile().mkdirs()); + artifactFile.getParentFile().mkdirs(), + "Failed to create parent directory"); } if (artifactFile.exists()) { - assertTrue("Failed to delete existing artifact file", artifactFile.delete()); + assertTrue(artifactFile.delete(), "Failed to delete existing artifact file"); } - assertTrue("Failed to create artifact file", artifactFile.createNewFile()); + assertTrue(artifactFile.createNewFile(), "Failed to create artifact file"); File signatureFile = new File(sourceDirectory, "maven-dependency-plugin-1.0.jar.asc"); if (!signatureFile.getParentFile().exists()) { assertTrue( - "Failed to create parent directory", - signatureFile.getParentFile().mkdirs()); + signatureFile.getParentFile().mkdirs(), + "Failed to create parent directory"); } if (signatureFile.exists()) { - assertTrue("Failed to delete existing signature file", signatureFile.delete()); + assertTrue(signatureFile.delete(), "Failed to delete existing signature file"); } - assertTrue("Failed to create signature file", signatureFile.createNewFile()); + assertTrue(signatureFile.createNewFile(), "Failed to create signature file"); Artifact artifact = stubFactory.createArtifact( "org.apache.maven.plugins", "maven-dependency-plugin", "1.0", Artifact.SCOPE_COMPILE); @@ -168,7 +178,7 @@ public void testCopySignatureFiles() throws Exception { mojo.execute(); File copiedSignatureFile = new File(mojo.outputDirectory, "maven-dependency-plugin-1.0.jar.asc"); - assertTrue("Signature file was not copied", copiedSignatureFile.exists()); + assertTrue(copiedSignatureFile.exists(), "Signature file was not copied"); // Clean up artifactFile.delete(); @@ -181,6 +191,7 @@ public void testCopySignatureFiles() throws Exception { * * @throws Exception in case of an error */ + @Test public void testMojo() throws Exception { mojo.execute(); Set artifacts = mojo.getProject().getArtifacts(); @@ -194,6 +205,7 @@ public void testMojo() throws Exception { } } + @Test public void testStripVersion() throws Exception { mojo.stripVersion = true; mojo.execute(); @@ -206,6 +218,7 @@ public void testStripVersion() throws Exception { } } + @Test public void testStripClassifier() throws Exception { mojo.stripClassifier = true; mojo.execute(); @@ -218,6 +231,7 @@ public void testStripClassifier() throws Exception { } } + @Test public void testUseBaseVersion() throws Exception { mojo.useBaseVersion = true; mojo.execute(); @@ -230,6 +244,7 @@ public void testUseBaseVersion() throws Exception { } } + @Test public void testNoTransitive() throws Exception { mojo.excludeTransitive = true; mojo.execute(); @@ -242,6 +257,7 @@ public void testNoTransitive() throws Exception { } } + @Test public void testExcludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); @@ -256,6 +272,7 @@ public void testExcludeType() throws Exception { } } + @Test public void testIncludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); @@ -283,6 +300,7 @@ public void testIncludeType() throws Exception { } } + @Test public void testExcludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); mojo.excludeArtifactIds = "one"; @@ -296,6 +314,7 @@ public void testExcludeArtifactId() throws Exception { } } + @Test public void testIncludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); @@ -323,6 +342,7 @@ public void testIncludeArtifactId() throws Exception { } } + @Test public void testIncludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); @@ -350,6 +370,7 @@ public void testIncludeGroupId() throws Exception { } } + @Test public void testExcludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); @@ -365,6 +386,7 @@ public void testExcludeGroupId() throws Exception { } } + @Test public void testExcludeMultipleGroupIds() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); @@ -381,6 +403,7 @@ public void testExcludeMultipleGroupIds() throws Exception { } } + @Test public void testExcludeClassifier() throws Exception { mojo.getProject().setArtifacts(stubFactory.getClassifiedArtifacts()); @@ -395,6 +418,7 @@ public void testExcludeClassifier() throws Exception { } } + @Test public void testIncludeClassifier() throws Exception { mojo.getProject().setArtifacts(stubFactory.getClassifiedArtifacts()); @@ -422,6 +446,7 @@ public void testIncludeClassifier() throws Exception { } } + @Test public void testSubPerType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); @@ -438,14 +463,17 @@ public void testSubPerType() throws Exception { } } + @Test public void testCDMClassifier() throws Exception { dotestClassifierType("jdk14", null); } + @Test public void testCDMType() throws Exception { dotestClassifierType(null, "sources"); } + @Test public void testCDMClassifierType() throws Exception { dotestClassifierType("jdk14", "sources"); } @@ -492,6 +520,7 @@ public void dotestClassifierType(String testClassifier, String testType) throws } } + @Test public void testArtifactResolutionException() throws MojoFailureException { dotestArtifactExceptions(); } @@ -515,6 +544,7 @@ public void dotestArtifactExceptions() throws MojoFailureException { * File.separatorChar + "target/test-classes/unit/copy-dependencies-test/test.zip" ); } */ + @Test public void testDontOverWriteRelease() throws MojoExecutionException, InterruptedException, IOException, MojoFailureException { @@ -544,6 +574,7 @@ public void testDontOverWriteRelease() assertEquals(time, copiedFile.lastModified()); } + @Test public void testOverWriteRelease() throws MojoExecutionException, IOException, MojoFailureException { Set artifacts = new HashSet<>(); @@ -572,6 +603,7 @@ public void testOverWriteRelease() throws MojoExecutionException, IOException, M assertEquals(1000L, timeCopyNow); } + @Test public void testDontOverWriteSnap() throws MojoExecutionException, IOException, MojoFailureException { Set artifacts = new HashSet<>(); @@ -600,6 +632,7 @@ public void testDontOverWriteSnap() throws MojoExecutionException, IOException, assertEquals(2000L, timeCopyNow); } + @Test public void testOverWriteSnap() throws MojoExecutionException, IOException, MojoFailureException { Set artifacts = new HashSet<>(); @@ -629,11 +662,13 @@ public void testOverWriteSnap() throws MojoExecutionException, IOException, Mojo assertEquals(1000L, timeCopyNow); } + @Test public void testGetDependencies() throws MojoExecutionException { assertTrue(mojo.getResolvedDependencies(true) .containsAll(mojo.getDependencySets(true).getResolvedDependencies())); } + @Test public void testExcludeProvidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); @@ -651,6 +686,7 @@ public void testExcludeProvidedScope() throws Exception { } } + @Test public void testExcludeSystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); @@ -668,6 +704,7 @@ public void testExcludeSystemScope() throws Exception { } } + @Test public void testExcludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); @@ -684,6 +721,7 @@ public void testExcludeCompileScope() throws Exception { } } + @Test public void testExcludeTestScope() throws IOException, MojoFailureException { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); @@ -697,6 +735,7 @@ public void testExcludeTestScope() throws IOException, MojoFailureException { } } + @Test public void testExcludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); @@ -713,6 +752,7 @@ public void testExcludeRuntimeScope() throws Exception { } } + @Test public void testCopyPom() throws Exception { mojo.setCopyPom(true); @@ -726,10 +766,11 @@ public void testCopyPom() throws Exception { for (Artifact artifact : artifacts) { String fileName = DependencyUtil.getFormattedFileName(artifact, false); File file = new File(mojo.outputDirectory, fileName.substring(0, fileName.length() - 4) + ".pom"); - assertTrue(file + " doesn't exist", file.exists()); + assertTrue(file.exists(), file + " doesn't exist"); } } + @Test public void testPrependGroupId() throws Exception { mojo.prependGroupId = true; mojo.execute(); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java index ae53378fb..54cdaf290 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java @@ -46,6 +46,12 @@ import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.project.MavenProject; import org.eclipse.aether.RepositorySystem; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestCopyDependenciesMojo2 extends AbstractDependencyMojoTestCase { @@ -61,8 +67,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); MavenProject project = new DependencyProjectStub(); @@ -94,6 +100,7 @@ protected void setUp() throws Exception { installLocalRepository(legacySupport); } + @Test public void testCopyDependenciesMojoIncludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "compile"; @@ -111,6 +118,7 @@ public void testCopyDependenciesMojoIncludeCompileScope() throws Exception { } } + @Test public void testCopyDependenciesMojoIncludeTestScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "test"; @@ -128,6 +136,7 @@ public void testCopyDependenciesMojoIncludeTestScope() throws Exception { } } + @Test public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "runtime"; @@ -145,6 +154,7 @@ public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception { } } + @Test public void testCopyDependenciesMojoIncludeprovidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "provided"; @@ -160,6 +170,7 @@ public void testCopyDependenciesMojoIncludeprovidedScope() throws Exception { } } + @Test public void testCopyDependenciesMojoIncludesystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "system"; @@ -175,6 +186,7 @@ public void testCopyDependenciesMojoIncludesystemScope() throws Exception { } } + @Test public void testSubPerArtifact() throws Exception { mojo.useSubDirectoryPerArtifact = true; @@ -190,6 +202,7 @@ public void testSubPerArtifact() throws Exception { } } + @Test public void testSubPerArtifactAndType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); mojo.useSubDirectoryPerArtifact = true; @@ -207,6 +220,7 @@ public void testSubPerArtifactAndType() throws Exception { } } + @Test public void testSubPerArtifactAndScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); mojo.useSubDirectoryPerArtifact = true; @@ -224,6 +238,7 @@ public void testSubPerArtifactAndScope() throws Exception { } } + @Test public void testRepositoryLayout() throws Exception { String baseVersion = "2.0-SNAPSHOT"; String groupId = "testGroupId"; @@ -296,9 +311,9 @@ private void assertArtifactExists(Artifact artifact, ArtifactRepository targetRe File file = new File(targetRepository.getBasedir(), pathOf); Path targetPath = Paths.get(file.getParent()); - assertTrue("Target path doesn't exist: " + targetPath, Files.isDirectory(targetPath)); + assertTrue(Files.isDirectory(targetPath), "Target path doesn't exist: " + targetPath); - assertTrue("File doesn't exist: " + file.getAbsolutePath(), file.exists()); + assertTrue(file.exists(), "File doesn't exist: " + file.getAbsolutePath()); Collection metas = artifact.getMetadataList(); for (ArtifactMetadata meta : metas) { @@ -308,6 +323,7 @@ private void assertArtifactExists(Artifact artifact, ArtifactRepository targetRe } } + @Test public void testSubPerArtifactRemoveVersion() throws Exception { mojo.useSubDirectoryPerArtifact = true; mojo.stripVersion = true; @@ -324,6 +340,7 @@ public void testSubPerArtifactRemoveVersion() throws Exception { } } + @Test public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); mojo.useSubDirectoryPerArtifact = true; @@ -342,6 +359,7 @@ public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { } } + @Test public void testSubPerArtifactRemoveType() throws Exception { mojo.useSubDirectoryPerArtifact = true; mojo.stripType = true; @@ -358,6 +376,7 @@ public void testSubPerArtifactRemoveType() throws Exception { } } + @Test public void testSubPerArtifactAndTypeRemoveType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); mojo.useSubDirectoryPerArtifact = true; diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java index eeb093818..efaeccc43 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java @@ -26,6 +26,11 @@ import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; 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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestIncludeExcludeUnpackDependenciesMojo extends AbstractDependencyMojoTestCase { private static final String PACKED_FILE = "test.zip"; @@ -48,8 +53,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -91,6 +96,7 @@ private void assertUnpacked(boolean unpacked, String fileName) { * * @throws Exception in case of errors */ + @Test public void testUnpackIncludesManyFiles() throws Exception { mojo.setIncludes("**/*1" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -105,6 +111,7 @@ public void testUnpackIncludesManyFiles() throws Exception { * * @throws Exception in case of errors */ + @Test public void testUnpackIncludesSingleFile() throws Exception { mojo.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -119,6 +126,7 @@ public void testUnpackIncludesSingleFile() throws Exception { * * @throws Exception in case of errors */ + @Test public void testUnpackIncludesAllFiles() throws Exception { mojo.setIncludes("**/*"); mojo.execute(); @@ -133,6 +141,7 @@ public void testUnpackIncludesAllFiles() throws Exception { * * @throws Exception in case of errors */ + @Test public void testUnpackExcludesManyFiles() throws Exception { mojo.setExcludes("**/*1" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -147,6 +156,7 @@ public void testUnpackExcludesManyFiles() throws Exception { * * @throws Exception in case of errors */ + @Test public void testUnpackExcludesSingleFile() throws Exception { mojo.setExcludes("**/test2" + UNPACKED_FILE_SUFFIX); mojo.execute(); @@ -161,6 +171,7 @@ public void testUnpackExcludesSingleFile() throws Exception { * * @throws Exception in case of errors */ + @Test public void testUnpackExcludesAllFiles() throws Exception { mojo.setExcludes("**/*"); mojo.execute(); @@ -170,6 +181,7 @@ public void testUnpackExcludesAllFiles() throws Exception { assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX); } + @Test public void testNoIncludeExcludes() throws Exception { mojo.execute(); assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestRenderDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestRenderDependenciesMojo.java index c42da77d8..5d4dc30a8 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestRenderDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestRenderDependenciesMojo.java @@ -29,6 +29,8 @@ import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; 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.assertj.core.api.Assertions.assertThat; @@ -45,8 +47,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { super.setUp(); final MavenProject project = new DependencyProjectStub(); @@ -66,6 +68,7 @@ protected void setUp() throws Exception { * It is useful when combined with JIB for example since several versions of the CRD do not support wildcard for * the classpath(s). */ + @Test public void testRender() throws Exception { final File rendered = new File(testDir, "render-dependencies.testRender.txt"); @@ -103,6 +106,7 @@ public void testRender() throws Exception { /** * Tests the rendering with a file template. */ + @Test public void testRenderFromFile() throws Exception { final File rendered = new File(testDir, "render-dependencies.testRenderFromFile.txt"); final File template = new File(testDir, "render-dependencies.testRenderFromFile.template.vm"); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java index 98ddc8135..fdc678f3c 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java @@ -40,6 +40,13 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.manager.ArchiverManager; import org.eclipse.aether.RepositorySystem; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestUnpackDependenciesMojo extends AbstractDependencyMojoTestCase { @@ -65,8 +72,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -138,6 +145,7 @@ public void assertMarkerFile(boolean val, Artifact artifact) { } } + @Test public void testMojo() throws Exception { mojo.execute(); for (Artifact artifact : mojo.getProject().getArtifacts()) { @@ -145,6 +153,7 @@ public void testMojo() throws Exception { } } + @Test public void testNoTransitive() throws Exception { mojo.excludeTransitive = true; mojo.execute(); @@ -153,6 +162,7 @@ public void testNoTransitive() throws Exception { } } + @Test public void testExcludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); mojo.excludeTypes = "jar"; @@ -163,6 +173,7 @@ public void testExcludeType() throws Exception { } } + @Test public void testExcludeProvidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.excludeScope = "provided"; @@ -174,6 +185,7 @@ public void testExcludeProvidedScope() throws Exception { } } + @Test public void testExcludeSystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.excludeScope = "system"; @@ -185,6 +197,7 @@ public void testExcludeSystemScope() throws Exception { } } + @Test public void testExcludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.excludeScope = "compile"; @@ -196,6 +209,7 @@ public void testExcludeCompileScope() throws Exception { } } + @Test public void testExcludeTestScope() throws IOException, MojoFailureException { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.excludeScope = "test"; @@ -208,6 +222,7 @@ public void testExcludeTestScope() throws IOException, MojoFailureException { } } + @Test public void testExcludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.excludeScope = "runtime"; @@ -219,6 +234,7 @@ public void testExcludeRuntimeScope() throws Exception { } } + @Test public void testIncludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); @@ -246,6 +262,7 @@ public void testIncludeType() throws Exception { } } + @Test public void testSubPerType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); mojo.useSubDirectoryPerType = true; @@ -256,6 +273,7 @@ public void testSubPerType() throws Exception { } } + @Test public void testSubPerArtifact() throws Exception { mojo.useSubDirectoryPerArtifact = true; mojo.execute(); @@ -265,6 +283,7 @@ public void testSubPerArtifact() throws Exception { } } + @Test public void testSubPerArtifactAndType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); mojo.useSubDirectoryPerArtifact = true; @@ -276,6 +295,7 @@ public void testSubPerArtifactAndType() throws Exception { } } + @Test public void testSubPerArtifactRemoveVersion() throws Exception { mojo.useSubDirectoryPerArtifact = true; mojo.stripVersion = true; @@ -286,6 +306,7 @@ public void testSubPerArtifactRemoveVersion() throws Exception { } } + @Test public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); mojo.useSubDirectoryPerArtifact = true; @@ -298,6 +319,7 @@ public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { } } + @Test public void testIncludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "compile"; @@ -309,6 +331,7 @@ public void testIncludeCompileScope() throws Exception { } } + @Test public void testIncludeTestScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "test"; @@ -321,6 +344,7 @@ public void testIncludeTestScope() throws Exception { } } + @Test public void testIncludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "runtime"; @@ -332,6 +356,7 @@ public void testIncludeRuntimeScope() throws Exception { } } + @Test public void testIncludeprovidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "provided"; @@ -342,6 +367,7 @@ public void testIncludeprovidedScope() throws Exception { } } + @Test public void testIncludesystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); mojo.includeScope = "system"; @@ -353,6 +379,7 @@ public void testIncludesystemScope() throws Exception { } } + @Test public void testIncludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); @@ -376,6 +403,7 @@ public void testIncludeArtifactId() throws Exception { } } + @Test public void testExcludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); mojo.excludeArtifactIds = "one"; @@ -389,6 +417,7 @@ public void testExcludeArtifactId() throws Exception { } } + @Test public void testExcludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); mojo.excludeGroupIds = "one"; @@ -399,6 +428,7 @@ public void testExcludeGroupId() throws Exception { } } + @Test public void testIncludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); mojo.includeGroupIds = "one"; @@ -425,14 +455,17 @@ public void testIncludeGroupId() throws Exception { } } + @Test public void testCDMClassifier() throws Exception { dotestClassifierType("jdk14", null); } + @Test public void testCDMType() throws Exception { dotestClassifierType(null, "zip"); } + @Test public void testCDMClassifierType() throws Exception { dotestClassifierType("jdk14", "war"); } @@ -477,6 +510,7 @@ public void dotestClassifierType(String testClassifier, String testType) throws } } + @Test public void testArtifactResolutionException() throws MojoFailureException { dotestArtifactExceptions(); } diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java index 932dbb564..2a68766e2 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java @@ -33,8 +33,13 @@ import org.apache.maven.plugins.dependency.utils.DependencyUtil; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.manager.ArchiverManager; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestUnpackDependenciesMojo2 extends AbstractDependencyMojoTestCase { @@ -55,8 +60,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -102,6 +107,7 @@ public File getUnpackedFile(Artifact artifact) { return unpacked; } + @Test public void testDontOverWriteRelease() throws MojoExecutionException, InterruptedException, IOException, MojoFailureException { @@ -120,6 +126,7 @@ public void testDontOverWriteRelease() assertUnpacked(release, false); } + @Test public void testOverWriteRelease() throws MojoExecutionException, InterruptedException, IOException, MojoFailureException { @@ -139,6 +146,7 @@ public void testOverWriteRelease() assertUnpacked(release, true); } + @Test public void testDontOverWriteSnap() throws MojoExecutionException, InterruptedException, IOException, MojoFailureException { @@ -159,6 +167,7 @@ public void testDontOverWriteSnap() assertUnpacked(snap, false); } + @Test public void testOverWriteSnap() throws MojoExecutionException, InterruptedException, IOException, MojoFailureException { @@ -179,6 +188,7 @@ public void testOverWriteSnap() assertUnpacked(snap, true); } + @Test public void testOverWriteIfNewer() throws MojoExecutionException, InterruptedException, IOException, MojoFailureException { diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java index 203d76546..ec4258610 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java @@ -28,10 +28,13 @@ import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -40,6 +43,7 @@ public class ExcludeReactorProjectsArtifactFilterTest extends AbstractDependencyMojoTestCase { + @Test public void testFilter() throws ArtifactFilterException { Artifact artifact1 = new ArtifactStub(); artifact1.setGroupId("org.apache.maven.plugins"); @@ -70,6 +74,7 @@ public void testFilter() throws ArtifactFilterException { verify(log, never()).debug(any(String.class)); } + @Test public void testFilterWithLogging() throws ArtifactFilterException { Artifact artifact = new ArtifactStub(); artifact.setGroupId("org.apache.maven.plugins"); diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilterTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilterTest.java index e1460e317..d4e4b196b 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilterTest.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilterTest.java @@ -24,10 +24,14 @@ import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; import static java.util.Collections.singletonList; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ExcludeReactorProjectsDependencyFilterTest extends AbstractDependencyMojoTestCase { + @Test public void testReject() { final Artifact artifact1 = new ArtifactStub(); artifact1.setGroupId("org.apache.maven.plugins"); @@ -53,6 +57,7 @@ public void testReject() { assertFalse(filter.test(dependency)); } + @Test public void testAccept() { final Artifact artifact1 = new ArtifactStub(); artifact1.setGroupId("org.apache.maven.plugins"); diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java index 9c48d72c8..476111544 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java @@ -29,7 +29,14 @@ import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class GoOfflineMojoTest extends AbstractDependencyMojoTestCase { private GoOfflineMojo subject; @@ -44,8 +51,8 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); MavenProject project = new DependencyProjectStub(); @@ -67,6 +74,7 @@ protected void setUp() throws Exception { private static final String VALID_GROUP = "org.junit.jupiter"; + @Test public void testExcludeGroupIds() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml"); @@ -102,6 +110,7 @@ public void testExcludeGroupIds() throws Exception { assertFalse(artifacts.contains(artifact2)); } + @Test public void testExcludeArtifactIds() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml"); @@ -137,6 +146,7 @@ public void testExcludeArtifactIds() throws Exception { assertFalse(artifacts.contains(artifact2)); } + @Test public void testExcludeScope() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml"); @@ -173,6 +183,7 @@ public void testExcludeScope() throws Exception { assertFalse(artifacts.contains(artifact2)); } + @Test public void testExcludeTypes() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml"); @@ -262,6 +273,7 @@ public void xtestExcludeClassifiers() throws Exception { private static final String CLASSIFIER_INCLUDE_PREFIX = "includeThisClassifier"; + @Test public void testIncludeGroupIds() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-gid-plugin-config.xml"); @@ -298,6 +310,7 @@ public void testIncludeGroupIds() throws Exception { assertTrue(artifacts.contains(artifact2)); } + @Test public void testIncludeArtifactIds() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-aid-plugin-config.xml"); @@ -334,6 +347,7 @@ public void testIncludeArtifactIds() throws Exception { assertTrue(artifacts.contains(artifact2)); } + @Test public void testIncludeScope() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-scope-plugin-config.xml"); @@ -374,6 +388,7 @@ public void testIncludeScope() throws Exception { assertFalse(artifacts.contains(artifact3)); } + @Test public void testIncludeTypes() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-types-plugin-config.xml"); diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java index 2af967760..9f7944bfe 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java @@ -26,6 +26,10 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; import org.apache.maven.plugins.dependency.utils.DependencyStatusSets; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class ResolveDependenciesMojoTest extends AbstractDependencyMojoTestCase { @@ -39,27 +43,31 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); } + @Test public void testDependencyStatusLog() throws IOException { Set artifacts = this.stubFactory.getMixedArtifacts(); doTestDependencyStatusLog(artifacts); } + @Test public void testDependencyStatusLogNullFiles() throws IOException { this.stubFactory.setCreateFiles(false); Set artifacts = this.stubFactory.getMixedArtifacts(); doTestDependencyStatusLog(artifacts); } + @Test public void testDependencyStatusEmptySet() { doTestDependencyStatusLog(new HashSet<>()); } + @Test public void testOptionalDependencyFormatting() throws IOException { Set set = new HashSet<>(); Artifact artifact = diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java index 2a5d2d843..c7e068f64 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java @@ -28,6 +28,13 @@ import org.apache.maven.plugins.dependency.utils.DependencySilentLog; import org.apache.maven.plugins.dependency.utils.DependencyStatusSets; import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestResolveMojo extends AbstractDependencyMojoTestCase { @@ -41,8 +48,8 @@ protected boolean shouldCreateFiles() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -58,6 +65,7 @@ protected void setUp() throws Exception { * * @throws Exception in case of errors. */ + @Test public void testResolveTestEnvironment() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml"); ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom); @@ -86,6 +94,7 @@ public void testResolveTestEnvironment() throws Exception { assertEquals(directArtifacts.size(), results.getResolvedDependencies().size()); } + @Test public void testSilent() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml"); ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom); diff --git a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java index b34fa55b4..51394ace2 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java @@ -45,6 +45,12 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.shared.dependency.graph.DependencyNode; import org.apache.maven.shared.dependency.graph.internal.DefaultDependencyNode; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests TreeMojo. @@ -69,8 +75,8 @@ protected boolean shouldUseFlattenedPath() { /* * @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp() */ - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); @@ -92,6 +98,7 @@ protected void setUp() throws Exception { * * @throws Exception in case of an error. */ + @Test public void testTreeTestEnvironment() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml"); TreeMojo mojo = (TreeMojo) lookupMojo("tree", testPom); @@ -128,6 +135,7 @@ public void testTreeTestEnvironment() throws Exception { * * @throws Exception in case of an error. */ + @Test public void testTreeDotSerializing() throws Exception { List contents = runTreeMojo("tree1.dot", "dot"); assertTrue(findString(contents, "digraph \"testGroupId:project:jar:1.0:compile\" {")); @@ -143,6 +151,7 @@ public void testTreeDotSerializing() throws Exception { * * @throws Exception in case of an error. */ + @Test public void testTreeGraphMLSerializing() throws Exception { List contents = runTreeMojo("tree1.graphml", "graphml"); @@ -159,6 +168,7 @@ public void testTreeGraphMLSerializing() throws Exception { * * @throws Exception in case of an error. */ + @Test public void testTreeTGFSerializing() throws Exception { List contents = runTreeMojo("tree1.tgf", "tgf"); assertTrue(findString(contents, "testGroupId:project:jar:1.0:compile")); @@ -169,6 +179,7 @@ public void testTreeTGFSerializing() throws Exception { /** * Test the JSON format serialization on DependencyNodes with circular dependence */ + @Test public void testTreeJsonCircularDependency() throws IOException { String outputFileName = testDir.getAbsolutePath() + File.separator + "tree1.json"; File outputFile = new File(outputFileName); @@ -196,6 +207,7 @@ public void testTreeJsonCircularDependency() throws IOException { /* * Test parsing of Json output and verify all key-value pairs */ + @Test public void testTreeJsonParsing() throws Exception { List contents = runTreeMojo("tree2.json", "json"); @@ -310,11 +322,11 @@ private void assertNodeEquals( DependencyNode actualNode) { Artifact actualArtifact = actualNode.getArtifact(); - assertEquals("group id", expectedGroupId, actualArtifact.getGroupId()); - assertEquals("artifact id", expectedArtifactId, actualArtifact.getArtifactId()); - assertEquals("type", expectedType, actualArtifact.getType()); - assertEquals("version", expectedVersion, actualArtifact.getVersion()); - assertEquals("scope", expectedScope, actualArtifact.getScope()); + assertEquals(expectedGroupId, actualArtifact.getGroupId(), "group id"); + assertEquals(expectedArtifactId, actualArtifact.getArtifactId(), "artifact id"); + assertEquals(expectedType, actualArtifact.getType(), "type"); + assertEquals(expectedVersion, actualArtifact.getVersion(), "version"); + assertEquals(expectedScope, actualArtifact.getScope(), "scope"); } private String createArtifactCoordinateString(DependencyNode actualNode) { diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyStatusSets.java b/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyStatusSets.java index 58b33a84a..0f791741c 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyStatusSets.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/TestDependencyStatusSets.java @@ -19,6 +19,8 @@ package org.apache.maven.plugins.dependency.utils; import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestDependencyStatusSets extends AbstractDependencyMojoTestCase { @@ -32,12 +34,13 @@ protected boolean shouldCreateFiles() { return true; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { // required for mojo lookups to work super.setUp(); } + @Test public void testDependencyStatusSettersGetters() { /* * DependencyStatusSets dss = new DependencyStatusSets(); Set set = new HashSet(); dss.setResolvedDependencies( @@ -49,6 +52,7 @@ public void testDependencyStatusSettersGetters() { */ } + @Test public void testDependencyStatusConstructor() { /* * Set r = new HashSet(); Set u = new HashSet(); Set s = new HashSet(); DependencyStatusSets dss = new diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestUnpackMarkerFileHandler.java b/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestUnpackMarkerFileHandler.java index af165728f..7e19108dc 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestUnpackMarkerFileHandler.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/markers/TestUnpackMarkerFileHandler.java @@ -33,6 +33,12 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + public class TestUnpackMarkerFileHandler extends AbstractMojoTestCase { List artifactItems = new ArrayList<>(); diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/translators/TestClassifierTypeTranslator.java b/src/test/java/org/apache/maven/plugins/dependency/utils/translators/TestClassifierTypeTranslator.java index 1ffea9631..55ec0f3a9 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/translators/TestClassifierTypeTranslator.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/translators/TestClassifierTypeTranslator.java @@ -30,6 +30,11 @@ import org.apache.maven.plugin.testing.SilentLog; import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author brianf @@ -51,8 +56,8 @@ protected boolean shouldUseFlattenedPath() { return false; } - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { super.setUp(); artifactHandlerManager = new DefaultArtifactHandlerManager(); @@ -62,10 +67,12 @@ protected void setUp() throws Exception { artifacts = factory.getMixedArtifacts(); } + @Test public void testNullClassifier() { doTestNullEmptyClassifier(null); } + @Test public void testEmptyClassifier() { doTestNullEmptyClassifier(""); } @@ -96,10 +103,12 @@ public void doTestNullEmptyClassifier(String classifier) { } } + @Test public void testNullType() { doTestNullEmptyType(null); } + @Test public void testEmptyType() { doTestNullEmptyType(""); } @@ -130,6 +139,7 @@ public void doTestNullEmptyType(String type) { } } + @Test public void testClassifierAndType() { String classifier = "jdk14"; String type = "sources"; @@ -154,6 +164,7 @@ public void testClassifierAndType() { } } + @Test public void testGetterSetter() { String classifier = "class"; String type = "type";