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.assertEquals;
23  
24  import org.eclipse.aether.version.Version;
25  
26  /**
27   */
28  abstract class AbstractVersionTest
29  {
30  
31      protected static final int X_LT_Y = -1;
32  
33      protected static final int X_EQ_Y = 0;
34  
35      protected static final int X_GT_Y = 1;
36  
37      protected abstract Version newVersion( String version );
38  
39      protected void assertOrder( int expected, String version1, String version2 )
40      {
41          Version v1 = newVersion( version1 );
42          Version v2 = newVersion( version2 );
43  
44          if ( expected > 0 )
45          {
46              assertEquals( "expected " + v1 + " > " + v2, 1, Integer.signum( v1.compareTo( v2 ) ) );
47              assertEquals( "expected " + v2 + " < " + v1, -1, Integer.signum( v2.compareTo( v1 ) ) );
48              assertEquals( "expected " + v1 + " != " + v2, false, v1.equals( v2 ) );
49              assertEquals( "expected " + v2 + " != " + v1, false, v2.equals( v1 ) );
50          }
51          else if ( expected < 0 )
52          {
53              assertEquals( "expected " + v1 + " < " + v2, -1, Integer.signum( v1.compareTo( v2 ) ) );
54              assertEquals( "expected " + v2 + " > " + v1, 1, Integer.signum( v2.compareTo( v1 ) ) );
55              assertEquals( "expected " + v1 + " != " + v2, false, v1.equals( v2 ) );
56              assertEquals( "expected " + v2 + " != " + v1, false, v2.equals( v1 ) );
57          }
58          else
59          {
60              assertEquals( "expected " + v1 + " == " + v2, 0, v1.compareTo( v2 ) );
61              assertEquals( "expected " + v2 + " == " + v1, 0, v2.compareTo( v1 ) );
62              assertEquals( "expected " + v1 + " == " + v2, true, v1.equals( v2 ) );
63              assertEquals( "expected " + v2 + " == " + v1, true, v2.equals( v1 ) );
64              assertEquals( "expected #(" + v1 + ") == #(" + v1 + ")", v1.hashCode(), v2.hashCode() );
65          }
66      }
67  
68      protected void assertSequence( String... versions )
69      {
70          for ( int i = 0; i < versions.length - 1; i++ )
71          {
72              for ( int j = i + 1; j < versions.length; j++ )
73              {
74                  assertOrder( X_LT_Y, versions[i], versions[j] );
75              }
76          }
77      }
78  
79  }