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 org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.DefaultArtifact;
23 import org.apache.maven.model.Dependency;
24 import org.apache.maven.project.MavenProject;
25 import org.junit.jupiter.api.Test;
26 import org.junit.jupiter.api.extension.ExtendWith;
27 import org.mockito.Mock;
28 import org.mockito.junit.jupiter.MockitoExtension;
29
30 import static java.util.Collections.singletonList;
31 import static org.junit.jupiter.api.Assertions.assertFalse;
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33 import static org.mockito.Mockito.when;
34
35 @ExtendWith(MockitoExtension.class)
36 class ExcludeReactorProjectsDependencyFilterTest {
37
38 @Mock
39 private MavenProject project;
40
41 @Test
42 void testReject() {
43 Artifact artifact1 = anArtifact();
44
45 when(project.getArtifact()).thenReturn(artifact1);
46
47 ExcludeReactorProjectsDependencyFilter filter =
48 new ExcludeReactorProjectsDependencyFilter(singletonList(project));
49
50 Dependency dependency = new Dependency();
51 dependency.setGroupId(artifact1.getGroupId());
52 dependency.setArtifactId(artifact1.getArtifactId());
53 dependency.setVersion(artifact1.getVersion());
54
55 assertFalse(filter.test(dependency));
56 }
57
58 @Test
59 void testAccept() {
60 Artifact artifact1 = anArtifact();
61
62 when(project.getArtifact()).thenReturn(artifact1);
63
64 ExcludeReactorProjectsDependencyFilter filter =
65 new ExcludeReactorProjectsDependencyFilter(singletonList(project));
66
67 Dependency dependency = new Dependency();
68 dependency.setGroupId("something-else");
69 dependency.setArtifactId(artifact1.getArtifactId());
70 dependency.setVersion(artifact1.getVersion());
71
72 assertTrue(filter.test(dependency));
73 }
74
75 private Artifact anArtifact() {
76 return new DefaultArtifact(
77 "org.apache.maven.plugins", "maven-dependency-plugin-dummy", "1.0", null, "jar", "", null);
78 }
79 }