View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.util.version;
20  
21  import org.eclipse.aether.version.Version;
22  
23  import static org.junit.jupiter.api.Assertions.*;
24  
25  abstract class AbstractVersionTest {
26  
27      protected static final int X_LT_Y = -1;
28  
29      protected static final int X_EQ_Y = 0;
30  
31      protected static final int X_GT_Y = 1;
32  
33      protected abstract Version newVersion(String version);
34  
35      protected void assertOrder(int expected, String version1, String version2) {
36          Version v1 = newVersion(version1);
37          Version v2 = newVersion(version2);
38  
39          if (expected > 0) {
40              assertEquals(1, Integer.signum(v1.compareTo(v2)), "expected " + v1 + " > " + v2);
41              assertEquals(-1, Integer.signum(v2.compareTo(v1)), "expected " + v2 + " < " + v1);
42              assertNotEquals(v1, v2, "expected " + v1 + " != " + v2);
43              assertNotEquals(v2, v1, "expected " + v2 + " != " + v1);
44          } else if (expected < 0) {
45              assertEquals(-1, Integer.signum(v1.compareTo(v2)), "expected " + v1 + " < " + v2);
46              assertEquals(1, Integer.signum(v2.compareTo(v1)), "expected " + v2 + " > " + v1);
47              assertNotEquals(v1, v2, "expected " + v1 + " != " + v2);
48              assertNotEquals(v2, v1, "expected " + v2 + " != " + v1);
49          } else {
50              assertEquals(0, v1.compareTo(v2), "expected " + v1 + " == " + v2);
51              assertEquals(0, v2.compareTo(v1), "expected " + v2 + " == " + v1);
52              assertEquals(v1, v2, "expected " + v1 + " == " + v2);
53              assertEquals(v2, v1, "expected " + v2 + " == " + v1);
54              assertEquals(v1.hashCode(), v2.hashCode(), "expected #(" + v1 + ") == #(" + v1 + ")");
55          }
56      }
57  
58      protected void assertSequence(String... versions) {
59          for (int i = 0; i < versions.length - 1; i++) {
60              for (int j = i + 1; j < versions.length; j++) {
61                  assertOrder(X_LT_Y, versions[i], versions[j]);
62              }
63          }
64      }
65  }