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