Version implements Comparable<Version> { public static Version of(String... strings) { return new Version(strings); } private  Version(String... strings); static Version of(String... strings); static Version unknown(); @Override boolean equals(Object o); @Override int compareTo(Version other); @Override int hashCode(); @Override String toString();  }
@Test public void shouldParseVersion() { assertThat(Version.of(""), is(Version.of("0"))); assertThat(Version.of("1"), is(Version.of("1"))); assertThat(Version.of("12"), is(Version.of("12"))); assertThat(Version.of("1.2"), is(Version.of("1", "2"))); assertThat(Version.of("12.34"), is(Version.of("12", "34"))); assertThat(Version.of("A"), is(Version.of("a"))); assertThat(Version.of("A"), is(Version.of("alpha"))); assertThat(Version.of("AB"), is(Version.of("ab"))); assertThat(Version.of("A.B"), is(Version.of("a", "b"))); assertThat(Version.of("A.B"), is(Version.of("alpha", "beta"))); assertThat(Version.of("AB.CD"), is(Version.of("ab", "cd"))); assertThat(Version.of("1A"), is(Version.of("1", "a"))); assertThat(Version.of("1A2B"), is(Version.of("1", "a", "2", "b"))); assertThat(Version.of(".1"), is(Version.of("0", "1"))); assertThat(Version.of(".A"), is(Version.of("0", "a"))); assertThat(Version.of("-1"), is(Version.of("0", "1"))); assertThat(Version.of("-A"), is(Version.of("0", "a"))); assertThat(Version.of("1."), is(Version.of("1"))); assertThat(Version.of("A."), is(Version.of("a"))); assertThat(Version.of("1-"), is(Version.of("1"))); assertThat(Version.of("A-"), is(Version.of("a"))); assertThat(Version.of("1.A"), is(Version.of("1", "a"))); assertThat(Version.of("1-A"), is(Version.of("1", "a"))); assertThat(Version.of("1.2.3-A"), is(Version.of("1", "2", "3", "a"))); assertThat(Version.of("1.2.3-A.B"), is(Version.of("1", "2", "3", "a", "b"))); assertThat(Version.of("1.0.0-SNAPSHOT"), is(Version.of("1", "0", "0", "SNAPSHOT"))); }
@Test public void shouldCompareVersions() { assertThat(Version.of(""), is(lessThan(Version.of("1")))); assertThat(Version.of("1"), is(lessThan(Version.of("2")))); assertThat(Version.of("12"), is(lessThan(Version.of("12.1")))); assertThat(Version.of("12.1"), is(lessThan(Version.of("12.2")))); assertThat(Version.of("12-A"), is(lessThan(Version.of("12")))); assertThat(Version.of("12-A"), is(lessThan(Version.of("12.1")))); assertThat(Version.of("1.2"), is(lessThan(Version.of("1.2.1")))); assertThat(Version.of("1.2.1"), is(lessThan(Version.of("1.2.2")))); assertThat(Version.of("1.2.1"), is(lessThan(Version.of("1.2.2-sp2")))); assertThat(Version.of("1.2-sp2"), is(lessThan(Version.of("1.2.1")))); assertThat(Version.of("1.2-SNAPSHOT"), is(lessThan(Version.of("1.2")))); assertThat(Version.of("1.2-SNAPSHOT"), is(lessThan(Version.of("1.2.1-SNAPSHOT")))); }