001    package org.apache.maven.artifact.versioning;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.List;
023    
024    import junit.framework.TestCase;
025    
026    import org.apache.maven.artifact.Artifact;
027    
028    /**
029     * Tests version range construction.
030     *
031     * @author <a href="mailto:brett@apache.org">Brett Porter</a>
032     */
033    public class VersionRangeTest
034        extends TestCase
035    {
036        private static final String CHECK_NUM_RESTRICTIONS = "check number of restrictions";
037    
038        private static final String CHECK_UPPER_BOUND = "check upper bound";
039    
040        private static final String CHECK_UPPER_BOUND_INCLUSIVE = "check upper bound is inclusive";
041    
042        private static final String CHECK_LOWER_BOUND = "check lower bound";
043    
044        private static final String CHECK_LOWER_BOUND_INCLUSIVE = "check lower bound is inclusive";
045    
046        private static final String CHECK_VERSION_RECOMMENDATION = "check version recommended";
047    
048        private static final String CHECK_SELECTED_VERSION_KNOWN = "check selected version known";
049    
050        private static final String CHECK_SELECTED_VERSION = "check selected version";
051    
052        public void testRange()
053            throws InvalidVersionSpecificationException, OverConstrainedVersionException
054        {
055            Artifact artifact = null;
056            
057            VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" );
058            List<Restriction> restrictions = range.getRestrictions();
059            assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
060            Restriction restriction = (Restriction) restrictions.get( 0 );
061            assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
062            assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
063            assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
064            assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
065            assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
066            assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
067            assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
068    
069            range = VersionRange.createFromVersionSpec( "1.0" );
070            assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() );
071            restrictions = range.getRestrictions();
072            assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
073            restriction = (Restriction) restrictions.get( 0 );
074            assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
075            assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
076            assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
077            assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
078            assertTrue( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
079            assertEquals( CHECK_SELECTED_VERSION, "1.0", range.getSelectedVersion( artifact ).toString() );
080    
081            range = VersionRange.createFromVersionSpec( "[1.0]" );
082            restrictions = range.getRestrictions();
083            assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
084            restriction = (Restriction) restrictions.get( 0 );
085            assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
086            assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
087            assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
088            assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
089            assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
090            assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
091            assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
092    
093            range = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
094            restrictions = range.getRestrictions();
095            assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
096            restriction = (Restriction) restrictions.get( 0 );
097            assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
098            assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
099            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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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        }
665    
666        public void testSnapshotRangeBoundsCanContainSnapshots()
667            throws InvalidVersionSpecificationException
668        {
669            VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2-SNAPSHOT]" );
670    
671            assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
672            assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) );
673    
674            range = VersionRange.createFromVersionSpec( "[1.0-SNAPSHOT,1.2]" );
675    
676            assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
677            assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
678        }
679    
680        public void testSnapshotSoftVersionCanContainSnapshot()
681            throws InvalidVersionSpecificationException
682        {
683            VersionRange range = VersionRange.createFromVersionSpec( "1.0-SNAPSHOT" );
684    
685            assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
686        }
687    
688        private void checkInvalidRange( String version )
689        {
690            try
691            {
692                VersionRange.createFromVersionSpec( version );
693                fail( "Version " + version + " should have failed to construct" );
694            }
695            catch ( InvalidVersionSpecificationException expected )
696            {
697                // expected
698            }
699        }
700    
701        public void testContains() throws InvalidVersionSpecificationException
702        {
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        {
718            VersionRange vr = null;
719    
720            vr = VersionRange.createFromVersionSpec( requiredVersionRange );
721    
722            return vr.containsVersion( actualVersion );
723        }
724    
725        public void testOrder0()
726        {
727            // assertTrue( new DefaultArtifactVersion( "1.0-alpha10" ).compareTo( new DefaultArtifactVersion( "1.0-alpha1" ) ) > 0 );
728        }
729    }