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.Assert.assertEquals;
24  import static org.junit.Assert.assertFalse;
25  import static org.junit.Assert.assertTrue;
26  
27  /**
28   */
29  abstract class AbstractVersionTest {
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          Version v1 = newVersion(version1);
41          Version v2 = newVersion(version2);
42  
43          if (expected > 0) {
44              assertEquals("expected " + v1 + " > " + v2, 1, Integer.signum(v1.compareTo(v2)));
45              assertEquals("expected " + v2 + " < " + v1, -1, Integer.signum(v2.compareTo(v1)));
46              assertFalse("expected " + v1 + " != " + v2, v1.equals(v2));
47              assertFalse("expected " + v2 + " != " + v1, v2.equals(v1));
48          } else if (expected < 0) {
49              assertEquals("expected " + v1 + " < " + v2, -1, Integer.signum(v1.compareTo(v2)));
50              assertEquals("expected " + v2 + " > " + v1, 1, Integer.signum(v2.compareTo(v1)));
51              assertFalse("expected " + v1 + " != " + v2, v1.equals(v2));
52              assertFalse("expected " + v2 + " != " + v1, v2.equals(v1));
53          } else {
54              assertEquals("expected " + v1 + " == " + v2, 0, v1.compareTo(v2));
55              assertEquals("expected " + v2 + " == " + v1, 0, v2.compareTo(v1));
56              assertTrue("expected " + v1 + " == " + v2, v1.equals(v2));
57              assertTrue("expected " + v2 + " == " + v1, v2.equals(v1));
58              assertEquals("expected #(" + v1 + ") == #(" + v1 + ")", v1.hashCode(), v2.hashCode());
59          }
60      }
61  
62      protected void assertSequence(String... versions) {
63          for (int i = 0; i < versions.length - 1; i++) {
64              for (int j = i + 1; j < versions.length; j++) {
65                  assertOrder(X_LT_Y, versions[i], versions[j]);
66              }
67          }
68      }
69  }