Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -111,6 +118,7 @@ public void testTransitive() throws Exception {
*
* @throws Exception in case of errors
*/
@Test
public void testRemoteRepositories() throws Exception {
setVariableValueToObject(
mojo,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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<String> expectedLogArgs = Files.readAllLines(path);
Expand All @@ -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<String> expectedLogArgs = Files.readAllLines(path);
Expand All @@ -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<String> expectedLogArgs = Files.readAllLines(path);
Expand All @@ -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<String> expectedLogArgs = Files.readAllLines(path);
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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);
Expand Down
29 changes: 26 additions & 3 deletions src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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");
}
Expand All @@ -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));
Expand Down
Loading
Loading