1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency;
20
21 import java.util.Set;
22
23 import org.apache.maven.api.plugin.testing.InjectMojo;
24 import org.apache.maven.api.plugin.testing.MojoParameter;
25 import org.apache.maven.api.plugin.testing.MojoTest;
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
28 import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
29 import org.apache.maven.plugins.dependency.utils.DependencySilentLog;
30 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
31 import org.apache.maven.project.MavenProject;
32 import org.junit.jupiter.api.BeforeEach;
33 import org.junit.jupiter.api.Test;
34
35 import static org.junit.jupiter.api.Assertions.assertEquals;
36 import static org.junit.jupiter.api.Assertions.assertFalse;
37 import static org.junit.jupiter.api.Assertions.assertNotNull;
38 import static org.junit.jupiter.api.Assertions.assertTrue;
39
40 @MojoTest
41 class TestCollectMojo {
42
43 private DependencyArtifactStubFactory stubFactory;
44
45 @BeforeEach
46 void setUp() throws Exception {
47 stubFactory = new DependencyArtifactStubFactory(null, false);
48 }
49
50
51
52
53
54
55 @Test
56 @InjectMojo(goal = "collect")
57 void testCollectTestEnvironment(CollectDependenciesMojo mojo) throws Exception {
58
59 assertNotNull(mojo);
60 assertNotNull(mojo.getProject());
61 MavenProject project = mojo.getProject();
62
63 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
64 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
65 artifacts.addAll(directArtifacts);
66
67 project.setArtifacts(artifacts);
68 project.setDependencyArtifacts(directArtifacts);
69
70 mojo.execute();
71 DependencyStatusSets results = mojo.getResults();
72 assertNotNull(results);
73 assertEquals(artifacts.size(), results.getResolvedDependencies().size());
74 }
75
76
77
78
79
80
81 @Test
82 @InjectMojo(goal = "collect")
83 @MojoParameter(name = "excludeTransitive", value = "true")
84 void testCollectTestEnvironmentExcludeTransitive(CollectDependenciesMojo mojo) throws Exception {
85 assertNotNull(mojo);
86 assertNotNull(mojo.getProject());
87 MavenProject project = mojo.getProject();
88
89 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
90 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
91 artifacts.addAll(directArtifacts);
92
93 project.setArtifacts(artifacts);
94 project.setDependencyArtifacts(directArtifacts);
95
96 mojo.execute();
97 DependencyStatusSets results = mojo.getResults();
98 assertNotNull(results);
99 assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
100 }
101
102 @Test
103 @InjectMojo(goal = "collect")
104 void testSilent(CollectDependenciesMojo mojo) throws Exception {
105 assertFalse(mojo.getLog() instanceof DependencySilentLog);
106
107 mojo.setSilent(true);
108 assertTrue(mojo.getLog() instanceof DependencySilentLog);
109
110 mojo.setSilent(false);
111 assertFalse(mojo.getLog() instanceof DependencySilentLog);
112 }
113 }