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.resolvers;
20
21 import java.io.IOException;
22 import java.util.HashSet;
23 import java.util.Set;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.versioning.VersionRange;
27 import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
28 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
29
30 public class ResolveDependenciesMojoTest extends AbstractDependencyMojoTestCase {
31 protected void setUp() throws Exception {
32
33 super.setUp("dss", true);
34 }
35
36 public void testDependencyStatusLog() throws IOException {
37 Set<Artifact> artifacts = this.stubFactory.getMixedArtifacts();
38 doTestDependencyStatusLog(artifacts);
39 }
40
41 public void testDependencyStatusLogNullFiles() throws IOException {
42 this.stubFactory.setCreateFiles(false);
43 Set<Artifact> artifacts = this.stubFactory.getMixedArtifacts();
44 doTestDependencyStatusLog(artifacts);
45 }
46
47 public void testDependencyStatusEmptySet() {
48 doTestDependencyStatusLog(new HashSet<>());
49 }
50
51 public void testOptionalDependencyFormatting() throws IOException {
52 Set<Artifact> set = new HashSet<>();
53 Artifact artifact =
54 stubFactory.createArtifact("g", "a", VersionRange.createFromVersion("1.0"), "test", "jar", null, true);
55 set.add(artifact);
56 doTestDependencyStatusLog(set);
57 ResolveDependenciesMojo mojo = newMojo(new DependencyStatusSets());
58 mojo.results.setResolvedDependencies(set);
59 String output = mojo.getOutput(false, true, false);
60 assertTrue(output.contains("g:a:jar:1.0:test (optional)" + System.lineSeparator()));
61 }
62
63 public void doTestDependencyStatusLog(Set<Artifact> artifacts) {
64
65
66
67 ResolveDependenciesMojo mojo = newMojo(new DependencyStatusSets());
68 mojo.getOutput(false, true, false);
69 mojo.getOutput(true, true, false);
70
71 mojo = newMojo(new DependencyStatusSets(artifacts, null, null));
72 mojo.getOutput(false, true, false);
73 mojo.getOutput(true, true, false);
74
75 mojo = newMojo(new DependencyStatusSets(null, artifacts, null));
76 mojo.getOutput(false, true, false);
77 mojo.getOutput(true, true, false);
78
79 mojo = newMojo(new DependencyStatusSets(null, null, artifacts));
80 mojo.getOutput(false, true, false);
81 mojo.getOutput(true, true, false);
82
83 mojo = newMojo(new DependencyStatusSets(artifacts, artifacts, null));
84 mojo.getOutput(false, true, false);
85 mojo.getOutput(true, true, false);
86
87 mojo = newMojo(new DependencyStatusSets(null, artifacts, artifacts));
88 mojo.getOutput(false, true, false);
89 mojo.getOutput(true, true, false);
90
91 mojo = newMojo(new DependencyStatusSets(artifacts, null, artifacts));
92 mojo.getOutput(false, true, false);
93 mojo.getOutput(true, true, false);
94
95 mojo = newMojo(new DependencyStatusSets(artifacts, artifacts, artifacts));
96 mojo.getOutput(false, true, false);
97 mojo.getOutput(true, true, false);
98 mojo.getOutput(false, false, false);
99 mojo.getOutput(true, false, false);
100 }
101
102 private ResolveDependenciesMojo newMojo(final DependencyStatusSets dss) {
103 ResolveDependenciesMojo mojo = new ResolveDependenciesMojo();
104 mojo.results = dss;
105 return mojo;
106 }
107 }