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