View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }