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