1   package org.apache.maven.plugins.shade.mojo;
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.Collection;
23  import java.util.Collections;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * @author Benjamin Bentmann
29   */
30  public class ArtifactSelectorTest
31      extends TestCase
32  {
33  
34      private ArtifactSelector newSelector( Collection includes, Collection excludes, String groupPrefix )
35      {
36          return new ArtifactSelector( includes, excludes, groupPrefix );
37      }
38  
39      public void testIsSelected()
40      {
41          ArtifactSelector selector;
42  
43          selector = newSelector( null, null, null );
44          assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
45  
46          selector = newSelector( null, null, "" );
47          assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
48  
49          selector = newSelector( null, null, "gid" );
50          assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
51          assertTrue( selector.isSelected( new ArtifactId( "gid.test", "aid", "type", "cls" ) ) );
52          assertFalse( selector.isSelected( new ArtifactId( "id", "aid", "type", "cls" ) ) );
53  
54          selector = newSelector( Collections.EMPTY_SET, Collections.EMPTY_SET, null );
55          assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
56  
57          selector = newSelector( Collections.singleton( "gid:aid" ), Collections.EMPTY_SET, null );
58          assertTrue( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
59          assertFalse( selector.isSelected( new ArtifactId( "gid", "id", "type", "cls" ) ) );
60  
61          selector = newSelector( Collections.EMPTY_SET, Collections.singleton( "gid:aid" ), null );
62          assertFalse( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
63          assertTrue( selector.isSelected( new ArtifactId( "gid", "id", "type", "cls" ) ) );
64  
65          selector = newSelector( Collections.singleton( "gid:*" ), Collections.singleton( "*:aid" ), null );
66          assertTrue( selector.isSelected( new ArtifactId( "gid", "id", "type", "cls" ) ) );
67          assertFalse( selector.isSelected( new ArtifactId( "gid", "aid", "type", "cls" ) ) );
68          assertFalse( selector.isSelected( new ArtifactId( "gid.test", "id", "type", "cls" ) ) );
69      }
70  
71  }