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