aboutsummaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/test/java/com/yahoo/config/provision/VersionTest.java
blob: e5d9cb2c8c92688198ecfd8f944658c20b761a00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;

import com.yahoo.test.TotalOrderTester;
import org.junit.Test;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;
import com.google.common.testing.EqualsTester;

/**
 * @author Vegard Sjonfjell
 * @since 5.39
 */
public class VersionTest {
    @Test
    public void testConstructFromIntegers() {
        Version exampleVersion = Version.fromIntValues(3, 2, 1);
        assertThat(exampleVersion.getMajor(), is(3));
        assertThat(exampleVersion.getMinor(), is(2));
        assertThat(exampleVersion.getMicro(), is(1));
    }

    @Test (expected = IllegalArgumentException.class)
    public void testConstructFromIntegersNegativesShouldFail() throws IllegalArgumentException {
        Version.fromIntValues(2, -1, 1);
    }

    @Test (expected = IllegalArgumentException.class)
    public void testConstructFromStringTooLongVersionStringShouldFail() throws IllegalArgumentException {
        Version.fromString("3.2.1.4");
    }

    @Test (expected = IllegalArgumentException.class)
    public void testConstructFromStringTooShortVersionStringShouldFail() throws IllegalArgumentException {
        Version.fromString("3.2");
    }

    @Test (expected = IllegalArgumentException.class)
    public void testConstructFromStringInvalidVersionStringShouldFail() throws IllegalArgumentException {
        Version.fromString("4.34.3a");
    }

    @Test
    public void testEncodeToStringRepresentation() {
        assertThat(Version.fromIntValues(3, 2, 1).toSerializedForm(), is("3.2.1"));
        assertThat(Version.fromIntValues(0, 0, 0).toSerializedForm(), is("0.0.0"));
    }

    @Test
    public void testEqualityAndHashCode() {
        new EqualsTester()
                .addEqualityGroup(Version.fromIntValues(3, 2, 1), Version.fromIntValues(3, 2, 1))
                .addEqualityGroup(Version.fromIntValues(1, 2, 3), Version.fromString("1.2.3"))
                .addEqualityGroup(Version.fromString("1.5.1"))
                .addEqualityGroup(Version.fromIntValues(1, 2, 1))
                .addEqualityGroup(Version.fromString("0.0.0"))
                .testEquals();
    }

    @Test
    public void testCompareTo() {
        new TotalOrderTester<Version>()
                .theseObjects(Version.fromIntValues(1, 1, 1), Version.fromIntValues(1, 1, 1))
                .areLessThan(Version.fromIntValues(2, 1, 1))
                .areLessThan(Version.fromIntValues(2, 2, 1))
                .areLessThan(Version.fromIntValues(2, 2, 2))
                .areLessThan(Version.fromIntValues(3, 0, 0))
                .testOrdering();
    }
}