View Javadoc
1   package org.apache.maven.shared.artifact.filter.collection;
2   
3   /* 
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
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
35          extends AbstractArtifactFeatureFilterTest
36  {
37  
38      @Before
39      public void setUp()
40          throws Exception
41      {
42          filterClass = GroupIdFilter.class;
43          ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
44          artifacts = factory.getGroupIdArtifacts();
45      }
46  
47      @Test
48      public void testParsing()
49          throws Exception
50      {
51          parsing();
52      }
53  
54      @Test
55      public void testFiltering()
56          throws Exception
57      {
58          Set<Artifact> result = filtering();
59          for ( Artifact artifact : result )
60          {
61              assertTrue( artifact.getGroupId().equals( "one" ) || artifact.getGroupId().equals( "two" ) );
62          }
63      }
64  
65      @Test
66      public void testFiltering2()
67          throws Exception
68      {
69          Set<Artifact> result = filtering2();
70          for ( Artifact artifact : result )
71          {
72              assertTrue( artifact.getGroupId().equals( "two" ) || artifact.getGroupId().equals( "four" ) );
73          }
74      }
75  
76      @Test
77      public void testFiltering3()
78          throws Exception
79      {
80          filtering3();
81      }
82  
83      @Test
84      public void testFiltering4()
85          throws Exception
86      {
87          // include o* from groupIds one,two should leave one
88          Set<Artifact> result = filtering();
89          assertEquals( 1, result.size() );
90          GroupIdFilter filter = new GroupIdFilter( "o", null );
91          result = filter.filter( result );
92          for ( Artifact artifact : result )
93          {
94              assertEquals( "one", artifact.getGroupId() );
95  
96          }
97  
98          // exclude on* from groupIds one,two should leave two
99          result = filtering();
100         assertEquals( 1, result.size() );
101         filter = new GroupIdFilter( null, "on" );
102         result = filter.filter( result );
103         for ( Artifact artifact : result )
104         {
105             assertEquals( "two", artifact.getGroupId() );
106 
107         }
108     }
109 
110     @Test
111     public void testMultipleInclude()
112         throws SecurityException, IllegalArgumentException, ArtifactFilterException
113     {
114         ArtifactsFilter filter = new GroupIdFilter( "one,two", null );
115 
116         assertEquals( 4, artifacts.size() );
117 
118         Set<Artifact> result = filter.filter( artifacts );
119 
120         assertEquals( 2, result.size() );
121     }
122 
123     @Test
124     public void testMultipleExclude()
125         throws SecurityException, IllegalArgumentException, ArtifactFilterException
126     {
127         ArtifactsFilter filter = new GroupIdFilter( null, "one,two" );
128 
129         assertEquals( 4, artifacts.size() );
130 
131         Set<Artifact> result = filter.filter( artifacts );
132 
133         assertEquals( 2, result.size() );
134     }
135 }