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 org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertFalse;
26  import static org.junit.Assert.assertTrue;
27  
28  /**
29   * @author Benjamin Bentmann
30   */
31  public class ArtifactIdTest
32  {
33  
34      @Test
35      public void testIdParsing()
36      {
37          ArtifactId id;
38  
39          id = new ArtifactId( (String) null );
40          assertEquals( "", id.getGroupId() );
41  
42          id = new ArtifactId( "" );
43          assertEquals( "", id.getGroupId() );
44  
45          id = new ArtifactId( "gid" );
46          assertEquals( "gid", id.getGroupId() );
47          assertEquals( "*", id.getArtifactId() );
48          assertEquals( "*", id.getType() );
49          assertEquals( "*", id.getClassifier() );
50  
51          id = new ArtifactId( "gid:" );
52          assertEquals( "gid", id.getGroupId() );
53          assertEquals( "", id.getArtifactId() );
54          assertEquals( "*", id.getType() );
55          assertEquals( "*", id.getClassifier() );
56  
57          id = new ArtifactId( ":aid" );
58          assertEquals( "", id.getGroupId() );
59          assertEquals( "aid", id.getArtifactId() );
60          assertEquals( "*", id.getType() );
61          assertEquals( "*", id.getClassifier() );
62  
63          id = new ArtifactId( "gid:aid" );
64          assertEquals( "gid", id.getGroupId() );
65          assertEquals( "aid", id.getArtifactId() );
66          assertEquals( "*", id.getType() );
67          assertEquals( "*", id.getClassifier() );
68  
69          id = new ArtifactId( "gid:aid:" );
70          assertEquals( "gid", id.getGroupId() );
71          assertEquals( "aid", id.getArtifactId() );
72          assertEquals( "*", id.getType() );
73          assertEquals( "", id.getClassifier() );
74  
75          id = new ArtifactId( "gid:aid:cls" );
76          assertEquals( "gid", id.getGroupId() );
77          assertEquals( "aid", id.getArtifactId() );
78          assertEquals( "*", id.getType() );
79          assertEquals( "cls", id.getClassifier() );
80  
81          id = new ArtifactId( "gid:aid:type:cls" );
82          assertEquals( "gid", id.getGroupId() );
83          assertEquals( "aid", id.getArtifactId() );
84          assertEquals( "type", id.getType() );
85          assertEquals( "cls", id.getClassifier() );
86  
87          id = new ArtifactId( "gid:aid::cls" );
88          assertEquals( "gid", id.getGroupId() );
89          assertEquals( "aid", id.getArtifactId() );
90          assertEquals( "", id.getType() );
91          assertEquals( "cls", id.getClassifier() );
92  
93          id = new ArtifactId( "gid:aid::" );
94          assertEquals( "gid", id.getGroupId() );
95          assertEquals( "aid", id.getArtifactId() );
96          assertEquals( "", id.getType() );
97          assertEquals( "", id.getClassifier() );
98  
99          id = new ArtifactId( "*:aid:type:cls" );
100         assertEquals( "*", id.getGroupId() );
101         assertEquals( "aid", id.getArtifactId() );
102         assertEquals( "type", id.getType() );
103         assertEquals( "cls", id.getClassifier() );
104 
105         id = new ArtifactId( "gid:*:type:cls" );
106         assertEquals( "gid", id.getGroupId() );
107         assertEquals( "*", id.getArtifactId() );
108         assertEquals( "type", id.getType() );
109         assertEquals( "cls", id.getClassifier() );
110 
111         id = new ArtifactId( "gid:aid:*:cls" );
112         assertEquals( "gid", id.getGroupId() );
113         assertEquals( "aid", id.getArtifactId() );
114         assertEquals( "*", id.getType() );
115         assertEquals( "cls", id.getClassifier() );
116 
117         id = new ArtifactId( "gid:aid:type:*" );
118         assertEquals( "gid", id.getGroupId() );
119         assertEquals( "aid", id.getArtifactId() );
120         assertEquals( "type", id.getType() );
121         assertEquals( "*", id.getClassifier() );
122     }
123 
124     @Test
125     public void testMatches()
126     {
127         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
128         assertFalse( new ArtifactId( "Gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
129         assertFalse( new ArtifactId( "gid", "Aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
130         assertFalse( new ArtifactId( "gid", "aid", "Type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
131         assertFalse( new ArtifactId( "gid", "aid", "type", "Cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
132 
133         assertTrue( new ArtifactId( "gid", "aid", "any", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
134         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
135         assertFalse( new ArtifactId( "id", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
136         assertFalse( new ArtifactId( "gid", "id", "type", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
137         assertFalse( new ArtifactId( "gid", "id", "type", "ls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
138 
139         assertTrue( new ArtifactId( "gid", "aid", "type", "" ).matches( new ArtifactId( "gid:aid" ) ) );
140         assertTrue( new ArtifactId( "gid", "aid", "any", "tests" ).matches( new ArtifactId( "gid:aid" ) ) );
141         assertFalse( new ArtifactId( "id", "aid", "type", "" ).matches( new ArtifactId( "gid:aid" ) ) );
142         assertFalse( new ArtifactId( "gid", "id", "type", "" ).matches( new ArtifactId( "gid:aid" ) ) );
143 
144         assertTrue( new ArtifactId( "gid", "aid", "type", "" ).matches( new ArtifactId( "gid" ) ) );
145         assertTrue( new ArtifactId( "gid", "id", "any", "any" ).matches( new ArtifactId( "gid" ) ) );
146         assertFalse( new ArtifactId( "id", "aid", "type", "" ).matches( new ArtifactId( "gid" ) ) );
147 
148         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "*:aid:type:cls" ) ) );
149         assertTrue( new ArtifactId( "any", "aid", "type", "cls" ).matches( new ArtifactId( "*:aid:type:cls" ) ) );
150         assertFalse( new ArtifactId( "any", "id", "type", "cls" ).matches( new ArtifactId( "*:aid:type:cls" ) ) );
151 
152         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:*:type:cls" ) ) );
153         assertTrue( new ArtifactId( "gid", "any", "type", "cls" ).matches( new ArtifactId( "gid:*:type:cls" ) ) );
154         assertFalse( new ArtifactId( "id", "any", "type", "cls" ).matches( new ArtifactId( "gid:*:type:cls" ) ) );
155 
156         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:*:cls" ) ) );
157         assertTrue( new ArtifactId( "gid", "aid", "any", "cls" ).matches( new ArtifactId( "gid:aid:*:cls" ) ) );
158         assertFalse( new ArtifactId( "id", "aid", "any", "cls" ).matches( new ArtifactId( "gid:aid:*:cls" ) ) );
159 
160         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:*" ) ) );
161         assertTrue( new ArtifactId( "gid", "aid", "type", "any" ).matches( new ArtifactId( "gid:aid:type:*" ) ) );
162         assertFalse( new ArtifactId( "id", "aid", "type", "any" ).matches( new ArtifactId( "gid:aid:type:*" ) ) );
163 
164         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:a*d" ) ) );
165         assertTrue( new ArtifactId( "gid", "ad", "type", "cls" ).matches( new ArtifactId( "gid:a*d" ) ) );
166         assertTrue( new ArtifactId( "gid", "a---d", "type", "cls" ).matches( new ArtifactId( "gid:a*d" ) ) );
167 
168         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
169         assertTrue( new ArtifactId( "gid", "a-d", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
170         assertFalse( new ArtifactId( "gid", "ad", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
171         assertFalse( new ArtifactId( "gid", "a---d", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
172     }
173 
174 }