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