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.shared.artifact.filter.collection;
20  
21  import java.util.Set;
22  
23  import org.apache.maven.artifact.Artifact;
24  import org.apache.maven.plugin.testing.ArtifactStubFactory;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import static org.junit.Assert.assertEquals;
29  import static org.junit.Assert.assertTrue;
30  
31  /**
32   * TestCases for GroupIdFilter
33   */
34  public class TestGroupIdFilter extends AbstractArtifactFeatureFilterTest {
35  
36      @Before
37      public void setUp() throws Exception {
38          filterClass = GroupIdFilter.class;
39          ArtifactStubFactory factory = new ArtifactStubFactory(null, false);
40          artifacts = factory.getGroupIdArtifacts();
41      }
42  
43      @Test
44      public void testParsing() throws Exception {
45          parsing();
46      }
47  
48      @Test
49      public void testFiltering() throws Exception {
50          Set<Artifact> result = filtering();
51          for (Artifact artifact : result) {
52              assertTrue(
53                      artifact.getGroupId().equals("one") || artifact.getGroupId().equals("two"));
54          }
55      }
56  
57      @Test
58      public void testFiltering2() throws Exception {
59          Set<Artifact> result = filtering2();
60          for (Artifact artifact : result) {
61              assertTrue(
62                      artifact.getGroupId().equals("two") || artifact.getGroupId().equals("four"));
63          }
64      }
65  
66      @Test
67      public void testFiltering3() throws Exception {
68          filtering3();
69      }
70  
71      @Test
72      public void testFiltering4() throws Exception {
73          // include o* from groupIds one,two should leave one
74          Set<Artifact> result = filtering();
75          assertEquals(1, result.size());
76          GroupIdFilter filter = new GroupIdFilter("o", null);
77          result = filter.filter(result);
78          for (Artifact artifact : result) {
79              assertEquals("one", artifact.getGroupId());
80          }
81  
82          // exclude on* from groupIds one,two should leave two
83          result = filtering();
84          assertEquals(1, result.size());
85          filter = new GroupIdFilter(null, "on");
86          result = filter.filter(result);
87          for (Artifact artifact : result) {
88              assertEquals("two", artifact.getGroupId());
89          }
90      }
91  
92      @Test
93      public void testMultipleInclude() throws SecurityException, IllegalArgumentException, ArtifactFilterException {
94          ArtifactsFilter filter = new GroupIdFilter("one,two", null);
95  
96          assertEquals(4, artifacts.size());
97  
98          Set<Artifact> result = filter.filter(artifacts);
99  
100         assertEquals(2, result.size());
101     }
102 
103     @Test
104     public void testMultipleExclude() throws SecurityException, IllegalArgumentException, ArtifactFilterException {
105         ArtifactsFilter filter = new GroupIdFilter(null, "one,two");
106 
107         assertEquals(4, artifacts.size());
108 
109         Set<Artifact> result = filter.filter(artifacts);
110 
111         assertEquals(2, result.size());
112     }
113 }