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