2 * Copyright 2018-present Open Networking Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.utils;
18 import org.junit.Test;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
27 public class VersionTest {
29 public void testVersionComparison() {
30 assertTrue(Version.from("1.0.0").compareTo(Version.from("2.0.0")) < 0);
31 assertTrue(Version.from("2.0.0").compareTo(Version.from("1.0.0")) > 0);
32 assertTrue(Version.from("1.0.0").compareTo(Version.from("0.1.0")) > 0);
33 assertTrue(Version.from("0.1.0").compareTo(Version.from("1.0.0")) < 0);
34 assertTrue(Version.from("0.1.0").compareTo(Version.from("0.1.1")) < 0);
35 assertTrue(Version.from("1.0.0").compareTo(Version.from("0.0.1")) > 0);
36 assertTrue(Version.from("1.1.1").compareTo(Version.from("1.0.3")) > 0);
37 assertTrue(Version.from("1.0.0").compareTo(Version.from("1.0.0-beta1")) > 0);
38 assertTrue(Version.from("1.0.0-rc2").compareTo(Version.from("1.0.0-rc1")) > 0);
39 assertTrue(Version.from("1.0.0-rc1").compareTo(Version.from("1.0.0-beta1")) > 0);
40 assertTrue(Version.from("2.0.0-beta1").compareTo(Version.from("1.0.0")) > 0);
41 assertTrue(Version.from("1.0.0-alpha1").compareTo(Version.from("1.0.0-SNAPSHOT")) > 0);
45 public void testVersionToString() {
46 assertEquals("1.0.0", Version.from("1.0.0").toString());
47 assertEquals("1.0.0-alpha1", Version.from("1.0.0-alpha1").toString());
48 assertEquals("1.0.0-beta1", Version.from("1.0.0-beta1").toString());
49 assertEquals("1.0.0-rc1", Version.from("1.0.0-rc1").toString());
50 assertEquals("1.0.0-SNAPSHOT", Version.from("1.0.0-SNAPSHOT").toString());
54 public void testInvalidVersions() {
55 assertIllegalArgument(() -> Version.from("1"));
56 assertIllegalArgument(() -> Version.from("1.0"));
57 assertIllegalArgument(() -> Version.from("1.0-beta1"));
58 assertIllegalArgument(() -> Version.from("1.0.0.0"));
59 assertIllegalArgument(() -> Version.from("1.0.0.0-beta1"));
60 assertIllegalArgument(() -> Version.from("1.0.0-not1"));
61 assertIllegalArgument(() -> Version.from("1.0.0-alpha"));
62 assertIllegalArgument(() -> Version.from("1.0.0-beta"));
63 assertIllegalArgument(() -> Version.from("1.0.0-rc"));
66 private void assertIllegalArgument(Runnable callback) {
70 } catch (IllegalArgumentException e) {