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