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.io.File;
22 import java.util.Set;
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.plugin.testing.SilentLog;
25 import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
26 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
27 import org.apache.maven.project.MavenProject;
28
29 public class TestCollectMojo extends AbstractDependencyMojoTestCase {
30
31 protected void setUp() throws Exception {
32
33 super.setUp("markers", false);
34 }
35
36
37
38
39
40
41 public void testCollectTestEnvironment() throws Exception {
42 File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
43 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
44
45 assertNotNull(mojo);
46 assertNotNull(mojo.getProject());
47 MavenProject project = mojo.getProject();
48
49 mojo.setSilent(true);
50 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
51 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
52 artifacts.addAll(directArtifacts);
53
54 project.setArtifacts(artifacts);
55 project.setDependencyArtifacts(directArtifacts);
56
57 mojo.execute();
58 DependencyStatusSets results = mojo.getResults();
59 assertNotNull(results);
60 assertEquals(artifacts.size(), results.getResolvedDependencies().size());
61 }
62
63
64
65
66
67
68 public void testCollectTestEnvironment_excludeTransitive() throws Exception {
69 File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
70 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
71
72 assertNotNull(mojo);
73 assertNotNull(mojo.getProject());
74 MavenProject project = mojo.getProject();
75
76 mojo.setSilent(true);
77 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
78 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
79 artifacts.addAll(directArtifacts);
80
81 project.setArtifacts(artifacts);
82 project.setDependencyArtifacts(directArtifacts);
83
84 setVariableValueToObject(mojo, "excludeTransitive", Boolean.TRUE);
85
86 mojo.execute();
87 DependencyStatusSets results = mojo.getResults();
88 assertNotNull(results);
89 assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
90 }
91
92 public void testSilent() throws Exception {
93 File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
94 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
95 mojo.setSilent(false);
96
97 assertFalse(mojo.getLog() instanceof SilentLog);
98 }
99 }