View Javadoc
1   package org.eclipse.aether.util.version;
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 static org.junit.Assert.*;
23  
24  import java.util.Collections;
25  
26  import org.eclipse.aether.version.InvalidVersionSpecificationException;
27  import org.eclipse.aether.version.VersionRange;
28  import org.junit.Test;
29  
30  public class UnionVersionRangeTest
31  {
32  
33      private VersionRange newRange( String range )
34      {
35          try
36          {
37              return new GenericVersionScheme().parseVersionRange( range );
38          }
39          catch ( InvalidVersionSpecificationException e )
40          {
41              throw new IllegalArgumentException( e );
42          }
43      }
44  
45      private void assertBound( String version, boolean inclusive, VersionRange.Bound bound )
46      {
47          if ( version == null )
48          {
49              assertNull( bound );
50          }
51          else
52          {
53              assertNotNull( bound );
54              assertNotNull( bound.getVersion() );
55              assertEquals( inclusive, bound.isInclusive() );
56              try
57              {
58                  assertEquals( new GenericVersionScheme().parseVersion( version ), bound.getVersion() );
59              }
60              catch ( InvalidVersionSpecificationException e )
61              {
62                  throw new IllegalArgumentException( e );
63              }
64          }
65      }
66  
67      @Test
68      public void testGetLowerBound()
69      {
70          VersionRange range = UnionVersionRange.from( Collections.<VersionRange> emptySet() );
71          assertBound( null, false, range.getLowerBound() );
72  
73          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "[3,4]" ) );
74          assertBound( "1", true, range.getLowerBound() );
75  
76          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "(,4]" ) );
77          assertBound( null, false, range.getLowerBound() );
78  
79          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "(1,4]" ) );
80          assertBound( "1", true, range.getLowerBound() );
81  
82          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "(0,4]" ) );
83          assertBound( "0", false, range.getLowerBound() );
84      }
85  
86      @Test
87      public void testGetUpperBound()
88      {
89          VersionRange range = UnionVersionRange.from( Collections.<VersionRange> emptySet() );
90          assertBound( null, false, range.getUpperBound() );
91  
92          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "[3,4]" ) );
93          assertBound( "4", true, range.getUpperBound() );
94  
95          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "[3,)" ) );
96          assertBound( null, false, range.getUpperBound() );
97  
98          range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "[1,2)" ) );
99          assertBound( "2", true, range.getUpperBound() );
100 
101         range = UnionVersionRange.from( newRange( "[1,2]" ), newRange( "[1,3)" ) );
102         assertBound( "3", false, range.getUpperBound() );
103     }
104 
105 }