View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.shade.mojo;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  
24  import org.junit.Test;
25  
26  import static org.junit.Assert.assertFalse;
27  import static org.junit.Assert.assertTrue;
28  
29  /**
30   * @author Benjamin Bentmann
31   */
32  public class ArtifactSelectorTest {
33  
34      private ArtifactSelector newSelector(Collection<String> includes, Collection<String> excludes, String groupPrefix) {
35          return new ArtifactSelector(includes, excludes, groupPrefix);
36      }
37  
38      @Test
39      public void testIsSelected() {
40          ArtifactSelector selector;
41  
42          selector = newSelector(null, null, null);
43          assertTrue(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
44  
45          selector = newSelector(null, null, "");
46          assertTrue(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
47  
48          selector = newSelector(null, null, "gid");
49          assertTrue(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
50          assertTrue(selector.isSelected(new ArtifactId("gid.test", "aid", "type", "cls")));
51          assertFalse(selector.isSelected(new ArtifactId("id", "aid", "type", "cls")));
52  
53          selector = newSelector(Collections.<String>emptySet(), Collections.<String>emptySet(), null);
54          assertTrue(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
55  
56          selector = newSelector(Collections.singleton("gid:aid"), Collections.<String>emptySet(), null);
57          assertTrue(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
58          assertFalse(selector.isSelected(new ArtifactId("gid", "id", "type", "cls")));
59  
60          selector = newSelector(Collections.<String>emptySet(), Collections.singleton("gid:aid"), null);
61          assertFalse(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
62          assertTrue(selector.isSelected(new ArtifactId("gid", "id", "type", "cls")));
63  
64          selector = newSelector(Collections.singleton("gid:*"), Collections.singleton("*:aid"), null);
65          assertTrue(selector.isSelected(new ArtifactId("gid", "id", "type", "cls")));
66          assertFalse(selector.isSelected(new ArtifactId("gid", "aid", "type", "cls")));
67          assertFalse(selector.isSelected(new ArtifactId("gid.test", "id", "type", "cls")));
68      }
69  }