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.List;
22  import java.util.Set;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.plugin.testing.ArtifactStubFactory;
26  import org.junit.Before;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertTrue;
31  
32  /**
33   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
34   */
35  public class TestTypeFilter
36  {
37      Set<Artifact> artifacts;
38  
39      @Before
40      public void setUp()
41          throws Exception
42      {
43          ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
44          artifacts = factory.getTypedArtifacts();
45      }
46  
47      @Test
48      public void testTypeParsing()
49      {
50          TypeFilter filter = new TypeFilter( "war,jar", "sources,zip," );
51          List<String> includes = filter.getIncludes();
52          List<String> excludes = filter.getExcludes();
53  
54          assertEquals( 2, includes.size() );
55          assertEquals( 2, excludes.size() );
56          assertEquals( "war", includes.get( 0 ) );
57          assertEquals( "jar", includes.get( 1 ) );
58          assertEquals( "sources", excludes.get( 0 ) );
59          assertEquals( "zip", excludes.get( 1 ) );
60      }
61  
62      @Test
63      public void testFiltering()
64      {
65          TypeFilter filter = new TypeFilter( "war,jar", "war,zip," );
66          Set<Artifact> result = filter.filter( artifacts );
67          assertEquals( 1, result.size() );
68  
69          for ( Artifact artifact : result )
70          {
71              assertEquals( "jar", artifact.getType() );
72          }
73      }
74  
75      @Test
76      public void testFiltering2()
77      {
78          TypeFilter filter = new TypeFilter( null, "war,jar," );
79          Set<Artifact> result = filter.filter( artifacts );
80          assertEquals( 3, result.size() );
81  
82          for ( Artifact artifact : result )
83          {
84              assertTrue( !artifact.getType().equals( "war" ) && !artifact.getType().equals( "jar" ) );
85          }
86      }
87  
88      @Test
89      public void testFiltering3()
90      {
91          TypeFilter filter = new TypeFilter( null, null );
92          Set<Artifact> result = filter.filter( artifacts );
93          assertEquals( 5, result.size() );
94      }
95  }