|
1 /* |
|
2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package jdk.jpackage.internal; |
|
24 |
|
25 import java.util.List; |
|
26 import java.util.stream.Collectors; |
|
27 import java.util.stream.Stream; |
|
28 import junit.framework.*; |
|
29 import org.junit.Test; |
|
30 import org.junit.runner.RunWith; |
|
31 import org.junit.runners.Parameterized; |
|
32 import org.junit.runners.Parameterized.Parameters; |
|
33 import static org.junit.Assert.*; |
|
34 |
|
35 @RunWith(Parameterized.class) |
|
36 public class CompareDottedVersionTest { |
|
37 |
|
38 public CompareDottedVersionTest(String version1, String version2, int result) { |
|
39 this.version1 = version1; |
|
40 this.version2 = version2; |
|
41 this.expectedResult = result; |
|
42 } |
|
43 |
|
44 @Parameters |
|
45 public static List<Object[]> data() { |
|
46 return List.of(new Object[][] { |
|
47 { "00.0.0", "0", 0 }, |
|
48 { "0.035", "0.0035", 0 }, |
|
49 { "1", "1", 0 }, |
|
50 { "2", "2.0", 0 }, |
|
51 { "2.00", "2.0", 0 }, |
|
52 { "1.2.3.4", "1.2.3.4.5", -1 }, |
|
53 { "34", "33", 1 }, |
|
54 { "34.0.78", "34.1.78", -1 } |
|
55 }); |
|
56 } |
|
57 |
|
58 @Test |
|
59 public void testIt() { |
|
60 int actualResult = compare(version1, version2); |
|
61 assertEquals(expectedResult, actualResult); |
|
62 |
|
63 int actualNegateResult = compare(version2, version1); |
|
64 assertEquals(actualResult, -1 * actualNegateResult); |
|
65 } |
|
66 |
|
67 private static int compare(String x, String y) { |
|
68 int result = new DottedVersion(x).compareTo(y); |
|
69 |
|
70 if (result < 0) { |
|
71 return -1; |
|
72 } |
|
73 |
|
74 if (result > 0) { |
|
75 return 1; |
|
76 } |
|
77 |
|
78 return 0; |
|
79 } |
|
80 |
|
81 private final String version1; |
|
82 private final String version2; |
|
83 private final int expectedResult; |
|
84 } |