1   package org.apache.maven.plugins.shade.filter;
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  import java.util.Collections;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * @author Benjamin Bentmann
28   */
29  public class SimpleFilterTest
30      extends TestCase
31  {
32  
33      public void testIsFiltered()
34      {
35          SimpleFilter filter;
36  
37          filter = new SimpleFilter( null, null, null );
38          assertFalse( filter.isFiltered( "a.properties" ) );
39          assertFalse( filter.isFiltered( "org/Test.class" ) );
40  
41          filter = new SimpleFilter( null, Collections.EMPTY_SET, Collections.EMPTY_SET );
42          assertFalse( filter.isFiltered( "a.properties" ) );
43          assertFalse( filter.isFiltered( "org/Test.class" ) );
44  
45          filter = new SimpleFilter( null, Collections.singleton( "org/Test.class" ), Collections.EMPTY_SET );
46          assertTrue( filter.isFiltered( "a.properties" ) );
47          assertFalse( filter.isFiltered( "org/Test.class" ) );
48          assertTrue( filter.isFiltered( "org/Test.properties" ) );
49  
50          filter = new SimpleFilter( null, Collections.EMPTY_SET, Collections.singleton( "org/Test.class" ) );
51          assertFalse( filter.isFiltered( "a.properties" ) );
52          assertTrue( filter.isFiltered( "org/Test.class" ) );
53          assertFalse( filter.isFiltered( "org/Test.properties" ) );
54  
55          filter = new SimpleFilter( null, Collections.singleton( "**/a.properties" ), Collections.EMPTY_SET );
56          assertFalse( filter.isFiltered( "a.properties" ) );
57          assertFalse( filter.isFiltered( "org/a.properties" ) );
58          assertFalse( filter.isFiltered( "org/maven/a.properties" ) );
59          assertTrue( filter.isFiltered( "org/maven/a.class" ) );
60  
61          filter = new SimpleFilter( null, Collections.EMPTY_SET, Collections.singleton( "org/*" ) );
62          assertFalse( filter.isFiltered( "Test.class" ) );
63          assertTrue( filter.isFiltered( "org/Test.class" ) );
64          assertFalse( filter.isFiltered( "org/apache/Test.class" ) );
65  
66          filter = new SimpleFilter( null, Collections.EMPTY_SET, Collections.singleton( "org/**" ) );
67          assertFalse( filter.isFiltered( "Test.class" ) );
68          assertTrue( filter.isFiltered( "org/Test.class" ) );
69          assertTrue( filter.isFiltered( "org/apache/Test.class" ) );
70  
71          filter = new SimpleFilter( null, Collections.EMPTY_SET, Collections.singleton( "org/" ) );
72          assertFalse( filter.isFiltered( "Test.class" ) );
73          assertTrue( filter.isFiltered( "org/Test.class" ) );
74          assertTrue( filter.isFiltered( "org/apache/Test.class" ) );
75      }
76  
77  }