1 package org.apache.maven.artifact.versioning;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.junit.jupiter.api.Test;
26
27 import static org.junit.jupiter.api.Assertions.assertEquals;
28 import static org.junit.jupiter.api.Assertions.assertFalse;
29 import static org.junit.jupiter.api.Assertions.assertNull;
30 import static org.junit.jupiter.api.Assertions.assertSame;
31 import static org.junit.jupiter.api.Assertions.assertThrows;
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33
34
35
36
37
38
39 public class VersionRangeTest
40 {
41 private static final String CHECK_NUM_RESTRICTIONS = "check number of restrictions";
42
43 private static final String CHECK_UPPER_BOUND = "check upper bound";
44
45 private static final String CHECK_UPPER_BOUND_INCLUSIVE = "check upper bound is inclusive";
46
47 private static final String CHECK_LOWER_BOUND = "check lower bound";
48
49 private static final String CHECK_LOWER_BOUND_INCLUSIVE = "check lower bound is inclusive";
50
51 private static final String CHECK_VERSION_RECOMMENDATION = "check version recommended";
52
53 private static final String CHECK_SELECTED_VERSION_KNOWN = "check selected version known";
54
55 private static final String CHECK_SELECTED_VERSION = "check selected version";
56
57 @Test
58 public void testRange()
59 throws InvalidVersionSpecificationException, OverConstrainedVersionException
60 {
61 Artifact artifact = null;
62
63 VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" );
64 List<Restriction> restrictions = range.getRestrictions();
65 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
66 Restriction restriction = restrictions.get( 0 );
67 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
68 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
69 assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
70 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
71 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
72 assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
73 assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
74
75 range = VersionRange.createFromVersionSpec( "1.0" );
76 assertEquals( "1.0", range.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
77 restrictions = range.getRestrictions();
78 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
79 restriction = restrictions.get( 0 );
80 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
81 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
82 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
83 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
84 assertTrue( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
85 assertEquals( "1.0", range.getSelectedVersion( artifact ).toString(), CHECK_SELECTED_VERSION );
86
87 range = VersionRange.createFromVersionSpec( "[1.0]" );
88 restrictions = range.getRestrictions();
89 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
90 restriction = restrictions.get( 0 );
91 assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
92 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
93 assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
94 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
95 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
96 assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
97 assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
98
99 range = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
100 restrictions = range.getRestrictions();
101 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
102 restriction = restrictions.get( 0 );
103 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
104 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
105 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
106 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
107 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
108 assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
109 assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
110
111 range = VersionRange.createFromVersionSpec( "[1.0,2.0)" );
112 restrictions = range.getRestrictions();
113 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
114 restriction = restrictions.get( 0 );
115 assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
116 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
117 assertEquals( "2.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
118 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
119 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
120 assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
121 assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
122
123 range = VersionRange.createFromVersionSpec( "[1.5,)" );
124 restrictions = range.getRestrictions();
125 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
126 restriction = restrictions.get( 0 );
127 assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
128 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
129 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
130 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
131 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
132 assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
133 assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
134
135 range = VersionRange.createFromVersionSpec( "(,1.0],[1.2,)" );
136 restrictions = range.getRestrictions();
137 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
138 restriction = restrictions.get( 0 );
139 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
140 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
141 assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
142 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
143 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
144 restriction = restrictions.get( 1 );
145 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
146 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
147 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
148 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
149 assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
150 assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
151 assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
152
153 range = VersionRange.createFromVersionSpec( "[1.0,)" );
154 assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
155
156 range = VersionRange.createFromVersionSpec( "[1.0,1.1-SNAPSHOT]" );
157 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
158
159 range = VersionRange.createFromVersionSpec( "[5.0.9.0,5.0.10.0)" );
160 assertTrue( range.containsVersion( new DefaultArtifactVersion( "5.0.9.0" ) ) );
161 }
162
163 @Test
164 public void testSameUpperAndLowerBoundRoundtrip() throws InvalidVersionSpecificationException
165 {
166 VersionRange range = VersionRange.createFromVersionSpec( "[1.0]" );
167 VersionRange range2 = VersionRange.createFromVersionSpec( range.toString() );
168 assertEquals( range, range2 );
169 }
170
171 @Test
172 public void testInvalidRanges()
173 {
174 checkInvalidRange( "(1.0)" );
175 checkInvalidRange( "[1.0)" );
176 checkInvalidRange( "(1.0]" );
177 checkInvalidRange( "(1.0,1.0]" );
178 checkInvalidRange( "[1.0,1.0)" );
179 checkInvalidRange( "(1.0,1.0)" );
180 checkInvalidRange( "[1.1,1.0]" );
181 checkInvalidRange( "[1.0,1.2),1.3" );
182
183 checkInvalidRange( "[1.0,1.2),(1.1,1.3]" );
184
185 checkInvalidRange( "[1.1,1.3),(1.0,1.2]" );
186
187 checkInvalidRange( "(1.1,1.2],[1.0,1.1)" );
188 }
189
190 @Test
191 public void testIntersections()
192 throws InvalidVersionSpecificationException
193 {
194 VersionRange range1 = VersionRange.createFromVersionSpec( "1.0" );
195 VersionRange range2 = VersionRange.createFromVersionSpec( "1.1" );
196 VersionRange mergedRange = range1.restrict( range2 );
197
198
199 assertEquals( "1.0", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
200 List<Restriction> restrictions = mergedRange.getRestrictions();
201 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
202 Restriction restriction = restrictions.get( 0 );
203 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
204 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
205 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
206 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
207
208 mergedRange = range2.restrict( range1 );
209 assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
210 restrictions = mergedRange.getRestrictions();
211 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
212 restriction = restrictions.get( 0 );
213 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
214 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
215 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
216 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
217
218
219 range1 = VersionRange.createFromVersionSpec( "[1.0,)" );
220 range2 = VersionRange.createFromVersionSpec( "1.1" );
221 mergedRange = range1.restrict( range2 );
222 assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
223 restrictions = mergedRange.getRestrictions();
224 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
225 restriction = restrictions.get( 0 );
226 assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
227 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
228 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
229 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
230
231 range1 = VersionRange.createFromVersionSpec( "[1.1,)" );
232 range2 = VersionRange.createFromVersionSpec( "1.1" );
233 mergedRange = range1.restrict( range2 );
234 assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
235 restrictions = mergedRange.getRestrictions();
236 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
237 restriction = restrictions.get( 0 );
238 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
239 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
240 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
241 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
242
243 range1 = VersionRange.createFromVersionSpec( "[1.1]" );
244 range2 = VersionRange.createFromVersionSpec( "1.1" );
245 mergedRange = range1.restrict( range2 );
246 assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
247 restrictions = mergedRange.getRestrictions();
248 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
249 restriction = restrictions.get( 0 );
250 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
251 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
252 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_UPPER_BOUND );
253 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
254
255 range1 = VersionRange.createFromVersionSpec( "(1.1,)" );
256 range2 = VersionRange.createFromVersionSpec( "1.1" );
257 mergedRange = range1.restrict( range2 );
258 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
259 restrictions = mergedRange.getRestrictions();
260 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
261 restriction = restrictions.get( 0 );
262 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
263 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
264 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
265 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
266
267 range1 = VersionRange.createFromVersionSpec( "[1.2,)" );
268 range2 = VersionRange.createFromVersionSpec( "1.1" );
269 mergedRange = range1.restrict( range2 );
270 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
271 restrictions = mergedRange.getRestrictions();
272 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
273 restriction = restrictions.get( 0 );
274 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
275 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
276 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
277 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
278
279 range1 = VersionRange.createFromVersionSpec( "(,1.2]" );
280 range2 = VersionRange.createFromVersionSpec( "1.1" );
281 mergedRange = range1.restrict( range2 );
282 assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
283 restrictions = mergedRange.getRestrictions();
284 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
285 restriction = restrictions.get( 0 );
286 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
287 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
288 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
289 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
290
291 range1 = VersionRange.createFromVersionSpec( "(,1.1]" );
292 range2 = VersionRange.createFromVersionSpec( "1.1" );
293 mergedRange = range1.restrict( range2 );
294 assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
295 restrictions = mergedRange.getRestrictions();
296 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
297 restriction = restrictions.get( 0 );
298 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
299 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
300 assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
301 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
302
303 range1 = VersionRange.createFromVersionSpec( "(,1.1)" );
304 range2 = VersionRange.createFromVersionSpec( "1.1" );
305 mergedRange = range1.restrict( range2 );
306 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
307 restrictions = mergedRange.getRestrictions();
308 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
309 restriction = restrictions.get( 0 );
310 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
311 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
312 assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
313 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
314
315 range1 = VersionRange.createFromVersionSpec( "(,1.0]" );
316 range2 = VersionRange.createFromVersionSpec( "1.1" );
317 mergedRange = range1.restrict( range2 );
318 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
319 restrictions = mergedRange.getRestrictions();
320 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
321 restriction = restrictions.get( 0 );
322 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
323 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
324 assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
325 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
326
327 range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" );
328 range2 = VersionRange.createFromVersionSpec( "1.2" );
329 mergedRange = range1.restrict( range2 );
330 assertEquals( "1.2", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
331 restrictions = mergedRange.getRestrictions();
332 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
333 restriction = restrictions.get( 0 );
334 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
335 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
336 assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
337 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
338 restriction = restrictions.get( 1 );
339 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
340 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
341 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
342 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
343
344 range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" );
345 range2 = VersionRange.createFromVersionSpec( "1.0.5" );
346 mergedRange = range1.restrict( range2 );
347 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
348 restrictions = mergedRange.getRestrictions();
349 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
350 restriction = restrictions.get( 0 );
351 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
352 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
353 assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
354 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
355 restriction = restrictions.get( 1 );
356 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
357 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
358 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
359 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
360
361 range1 = VersionRange.createFromVersionSpec( "(,1.1), (1.1,)" );
362 range2 = VersionRange.createFromVersionSpec( "1.1" );
363 mergedRange = range1.restrict( range2 );
364 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
365 restrictions = mergedRange.getRestrictions();
366 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
367 restriction = restrictions.get( 0 );
368 assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
369 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
370 assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
371 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
372 restriction = restrictions.get( 1 );
373 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
374 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
375 assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
376 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
377
378 range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" );
379 range2 = VersionRange.createFromVersionSpec( "(1.1,)" );
380 mergedRange = range1.restrict( range2 );
381 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
382 restrictions = mergedRange.getRestrictions();
383 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
384 restriction = restrictions.get( 0 );
385 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
386 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
387 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
388 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
389
390 range1 = VersionRange.createFromVersionSpec( "(,1.3)" );
391 range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
392 mergedRange = range1.restrict( range2 );
393 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
394 restrictions = mergedRange.getRestrictions();
395 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
396 restriction = restrictions.get( 0 );
397 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
398 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
399 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
400 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
401
402 range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" );
403 range2 = VersionRange.createFromVersionSpec( "[1.2,)" );
404 mergedRange = range1.restrict( range2 );
405 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
406 restrictions = mergedRange.getRestrictions();
407 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
408 restriction = restrictions.get( 0 );
409 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
410 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
411 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
412 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
413
414 range1 = VersionRange.createFromVersionSpec( "(,1.3]" );
415 range2 = VersionRange.createFromVersionSpec( "[1.2,1.4]" );
416 mergedRange = range1.restrict( range2 );
417 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
418 restrictions = mergedRange.getRestrictions();
419 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
420 restriction = restrictions.get( 0 );
421 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
422 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
423 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
424 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
425
426 range1 = VersionRange.createFromVersionSpec( "(1.2,1.3]" );
427 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
428 mergedRange = range1.restrict( range2 );
429 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
430 restrictions = mergedRange.getRestrictions();
431 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
432 restriction = restrictions.get( 0 );
433 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
434 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
435 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
436 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
437
438 range1 = VersionRange.createFromVersionSpec( "(1.2,1.3)" );
439 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
440 mergedRange = range1.restrict( range2 );
441 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
442 restrictions = mergedRange.getRestrictions();
443 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
444 restriction = restrictions.get( 0 );
445 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
446 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
447 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
448 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
449
450 range1 = VersionRange.createFromVersionSpec( "[1.2,1.3)" );
451 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
452 mergedRange = range1.restrict( range2 );
453 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
454 restrictions = mergedRange.getRestrictions();
455 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
456 restriction = restrictions.get( 0 );
457 assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
458 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
459 assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
460 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
461
462 range1 = VersionRange.createFromVersionSpec( "[1.0,1.1]" );
463 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
464 mergedRange = range1.restrict( range2 );
465 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
466 restrictions = mergedRange.getRestrictions();
467 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
468 restriction = restrictions.get( 0 );
469 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
470 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
471 assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
472 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
473
474 range1 = VersionRange.createFromVersionSpec( "[1.0,1.1)" );
475 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
476 mergedRange = range1.restrict( range2 );
477 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
478 restrictions = mergedRange.getRestrictions();
479 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
480
481 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
482 range2 = VersionRange.createFromVersionSpec( "[1.1]" );
483 mergedRange = range1.restrict( range2 );
484 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
485 restrictions = mergedRange.getRestrictions();
486 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
487 restriction = restrictions.get( 0 );
488 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
489 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
490 assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
491 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
492
493 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
494 range2 = VersionRange.createFromVersionSpec( "[1.4]" );
495 mergedRange = range1.restrict( range2 );
496 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
497 restrictions = mergedRange.getRestrictions();
498 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
499 restriction = restrictions.get( 0 );
500 assertEquals( "1.4", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
501 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
502 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
503 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
504
505 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
506 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
507 mergedRange = range1.restrict( range2 );
508 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
509 restrictions = mergedRange.getRestrictions();
510 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
511 restriction = restrictions.get( 0 );
512 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
513 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
514 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
515 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
516 restriction = restrictions.get( 1 );
517 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
518 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
519 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
520 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
521
522 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" );
523 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
524 mergedRange = range1.restrict( range2 );
525 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
526 restrictions = mergedRange.getRestrictions();
527 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
528 restriction = restrictions.get( 0 );
529 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
530 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
531 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
532 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
533 restriction = restrictions.get( 1 );
534 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
535 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
536 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
537 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
538
539 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
540 range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" );
541 mergedRange = range1.restrict( range2 );
542 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
543 restrictions = mergedRange.getRestrictions();
544 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
545 restriction = restrictions.get( 0 );
546 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
547 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
548 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
549 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
550 restriction = restrictions.get( 1 );
551 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
552 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
553 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
554 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
555
556 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" );
557 range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" );
558 mergedRange = range1.restrict( range2 );
559 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
560 restrictions = mergedRange.getRestrictions();
561 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
562 restriction = restrictions.get( 0 );
563 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
564 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
565 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
566 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
567 restriction = restrictions.get( 1 );
568 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
569 assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
570 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
571 assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
572
573 range1 = VersionRange.createFromVersionSpec( "(,1.1),(1.4,)" );
574 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
575 mergedRange = range1.restrict( range2 );
576 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
577 restrictions = mergedRange.getRestrictions();
578 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
579
580 range1 = VersionRange.createFromVersionSpec( "(,1.1],[1.4,)" );
581 range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" );
582 mergedRange = range1.restrict( range2 );
583 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
584 restrictions = mergedRange.getRestrictions();
585 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
586
587 range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
588 range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
589 mergedRange = range1.restrict( range2 );
590 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
591 restrictions = mergedRange.getRestrictions();
592 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
593
594 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
595 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.6,]" );
596 mergedRange = range1.restrict( range2 );
597 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
598 restrictions = mergedRange.getRestrictions();
599 assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
600 restriction = restrictions.get( 0 );
601 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
602 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
603 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
604 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
605 restriction = restrictions.get( 1 );
606 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
607 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
608 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
609 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
610
611 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
612 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,]" );
613 mergedRange = range1.restrict( range2 );
614 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
615 restrictions = mergedRange.getRestrictions();
616 assertEquals( 3, restrictions.size(), CHECK_NUM_RESTRICTIONS );
617 restriction = restrictions.get( 0 );
618 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
619 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
620 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
621 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
622 restriction = restrictions.get( 1 );
623 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
624 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
625 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
626 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
627 restriction = restrictions.get( 2 );
628 assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
629 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
630 assertEquals( "1.5", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
631 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
632
633 range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.7]" );
634 range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,1.6]" );
635 mergedRange = range1.restrict( range2 );
636 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
637 restrictions = mergedRange.getRestrictions();
638 assertEquals( 3, restrictions.size(), CHECK_NUM_RESTRICTIONS );
639 restriction = restrictions.get( 0 );
640 assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
641 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
642 assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
643 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
644 restriction = restrictions.get( 1 );
645 assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
646 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
647 assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
648 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
649 restriction = restrictions.get( 2 );
650 assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
651 assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
652 assertEquals( "1.6", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
653 assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
654
655
656 range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
657 range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
658 range1 = range1.restrict( range2 );
659 mergedRange = range1.restrict( range2 );
660 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
661 restrictions = mergedRange.getRestrictions();
662 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
663
664 range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
665 range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
666 range2 = range1.restrict( range2 );
667 mergedRange = range1.restrict( range2 );
668 assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
669 restrictions = mergedRange.getRestrictions();
670 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
671 }
672
673 @Test
674 public void testReleaseRangeBoundsContainsSnapshots()
675 throws InvalidVersionSpecificationException
676 {
677 VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2]" );
678
679 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
680 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) );
681 assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
682 }
683
684 @Test
685 public void testSnapshotRangeBoundsCanContainSnapshots()
686 throws InvalidVersionSpecificationException
687 {
688 VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2-SNAPSHOT]" );
689
690 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
691 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) );
692
693 range = VersionRange.createFromVersionSpec( "[1.0-SNAPSHOT,1.2]" );
694
695 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
696 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
697 }
698
699 @Test
700 public void testSnapshotSoftVersionCanContainSnapshot()
701 throws InvalidVersionSpecificationException
702 {
703 VersionRange range = VersionRange.createFromVersionSpec( "1.0-SNAPSHOT" );
704
705 assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
706 }
707
708 private void checkInvalidRange( String version )
709 {
710 assertThrows(
711 InvalidVersionSpecificationException.class,
712 () -> VersionRange.createFromVersionSpec( version ),
713 "Version " + version + " should have failed to construct" );
714 }
715
716 @Test
717 public void testContains() throws InvalidVersionSpecificationException
718 {
719 ArtifactVersion actualVersion = new DefaultArtifactVersion( "2.0.5" );
720 assertTrue( enforceVersion( "2.0.5", actualVersion ) );
721 assertTrue( enforceVersion( "2.0.4", actualVersion ) );
722 assertTrue( enforceVersion( "[2.0.5]", actualVersion ) );
723 assertFalse( enforceVersion( "[2.0.6,)", actualVersion ) );
724 assertFalse( enforceVersion( "[2.0.6]", actualVersion ) );
725 assertTrue( enforceVersion( "[2.0,2.1]", actualVersion ) );
726 assertFalse( enforceVersion( "[2.0,2.0.3]", actualVersion ) );
727 assertTrue( enforceVersion( "[2.0,2.0.5]", actualVersion ) );
728 assertFalse( enforceVersion( "[2.0,2.0.5)", actualVersion ) );
729 }
730
731 public boolean enforceVersion( String requiredVersionRange, ArtifactVersion actualVersion )
732 throws InvalidVersionSpecificationException
733 {
734 VersionRange vr = null;
735
736 vr = VersionRange.createFromVersionSpec( requiredVersionRange );
737
738 return vr.containsVersion( actualVersion );
739 }
740
741 @Test
742 public void testOrder0()
743 {
744
745 }
746
747 @Test
748 public void testCache()
749 throws InvalidVersionSpecificationException
750 {
751 VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2]" );
752 assertSame( range, VersionRange.createFromVersionSpec( "[1.0,1.2]" ) );
753
754 VersionRange spec = VersionRange.createFromVersionSpec( "1.0" );
755 assertSame( spec, VersionRange.createFromVersionSpec( "1.0" ) );
756 List<Restriction> restrictions = spec.getRestrictions();
757 assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
758
759 VersionRange version = VersionRange.createFromVersion( "1.0" );
760 assertSame( version, VersionRange.createFromVersion( "1.0" ) );
761 restrictions = version.getRestrictions();
762 assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
763
764 assertFalse( spec.equals( version ), "check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))" );
765 }
766 }