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.util.Collections;
22
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.model.Dependency;
25 import org.apache.maven.plugin.logging.Log;
26 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
27 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28 import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.shared.artifact.filter.resolve.Node;
31 import org.mockito.ArgumentCaptor;
32
33 import static java.util.Collections.singletonList;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.verify;
36 import static org.mockito.Mockito.when;
37
38 public class ExcludeReactorProjectsDependencyFilterTest extends AbstractDependencyMojoTestCase {
39 public void testReject() {
40 final Artifact artifact1 = new ArtifactStub();
41 artifact1.setGroupId("org.apache.maven.plugins");
42 artifact1.setArtifactId("maven-dependency-plugin-dummy");
43 artifact1.setVersion("1.0");
44
45 Artifact artifact2 = new ArtifactStub();
46 artifact2.setGroupId("org.apache.maven.plugins");
47 artifact2.setArtifactId("maven-dependency-plugin-other-dummy");
48 artifact2.setVersion("1.0");
49
50 MavenProject project = new MavenProjectStub();
51 project.setArtifact(artifact1);
52
53 Log log = mock(Log.class);
54 when(log.isDebugEnabled()).thenReturn(false);
55
56 ExcludeReactorProjectsDependencyFilter filter =
57 new ExcludeReactorProjectsDependencyFilter(singletonList(project), log);
58
59 Node node = () -> {
60 final Dependency result = new Dependency();
61 result.setGroupId(artifact1.getGroupId());
62 result.setArtifactId(artifact1.getArtifactId());
63 result.setVersion(artifact1.getVersion());
64 return result;
65 };
66
67 assertFalse(filter.accept(node, Collections.emptyList()));
68 }
69
70 public void testRejectWithLogging() {
71 final Artifact artifact1 = new ArtifactStub();
72 artifact1.setGroupId("org.apache.maven.plugins");
73 artifact1.setArtifactId("maven-dependency-plugin-dummy");
74 artifact1.setVersion("1.0");
75
76 Artifact artifact2 = new ArtifactStub();
77 artifact2.setGroupId("org.apache.maven.plugins");
78 artifact2.setArtifactId("maven-dependency-plugin-other-dummy");
79 artifact2.setVersion("1.0");
80
81 MavenProject project = new MavenProjectStub();
82 project.setArtifact(artifact1);
83
84 Log log = mock(Log.class);
85 when(log.isDebugEnabled()).thenReturn(true);
86
87 ExcludeReactorProjectsDependencyFilter filter =
88 new ExcludeReactorProjectsDependencyFilter(singletonList(project), log);
89
90 Node node = () -> {
91 final Dependency result = new Dependency();
92 result.setGroupId(artifact1.getGroupId());
93 result.setArtifactId(artifact1.getArtifactId());
94 result.setVersion(artifact1.getVersion());
95 return result;
96 };
97
98 filter.accept(node, Collections.emptyList());
99
100 ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
101 verify(log).debug(captor.capture());
102 assertTrue(captor.getValue().contains("Skipped dependency"));
103 }
104
105 public void testAccept() {
106 final Artifact artifact1 = new ArtifactStub();
107 artifact1.setGroupId("org.apache.maven.plugins");
108 artifact1.setArtifactId("maven-dependency-plugin-dummy");
109 artifact1.setVersion("1.0");
110
111 Artifact artifact2 = new ArtifactStub();
112 artifact2.setGroupId("org.apache.maven.plugins");
113 artifact2.setArtifactId("maven-dependency-plugin-other-dummy");
114 artifact2.setVersion("1.0");
115
116 MavenProject project = new MavenProjectStub();
117 project.setArtifact(artifact1);
118
119 Log log = mock(Log.class);
120 when(log.isDebugEnabled()).thenReturn(false);
121
122 ExcludeReactorProjectsDependencyFilter filter =
123 new ExcludeReactorProjectsDependencyFilter(singletonList(project), log);
124
125 Node node = () -> {
126 final Dependency result = new Dependency();
127 result.setGroupId("something-else");
128 result.setArtifactId(artifact1.getArtifactId());
129 result.setVersion(artifact1.getVersion());
130 return result;
131 };
132
133 assertTrue(filter.accept(node, Collections.emptyList()));
134 }
135 }