Version implements Comparable<Version> { public static Version fromString(String versionString) { if (versionString == null) { return new Version(0, 0, null); } try { String[] parts = versionString.split("\\."); String patchVersion = parts.length == 3 ? parts[2] : null; return new Version(parts.length > 0 ? Integer.parseInt(parts[0]) : 0, parts.length > 1 ? Integer.parseInt(parts[1]) : 0, patchVersion); } catch (NumberFormatException e) { throw new IllegalArgumentException(versionString + " is not a valid version string"); } } Version(int majorVersion, int minorVersion, String patchVersion); static Version fromString(String versionString); int getMajorVersion(); int getMinorVersion(); String getPatchVersion(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(Version other);  }
@Test public void correctEquals() throws Exception { assertThat(BASE_VERSION, is(equalTo(Version.fromString("1.7")))); assertThat(BASE_VERSION, is(not(equalTo(Version.fromString("1.7.1"))))); assertThat(BASE_VERSION, is(not(equalTo(null)))); assertThat(Version.fromString("1.7.2"), is(equalTo(Version.fromString("1.7.2")))); assertThat(Version.fromString("1.7.2"), is(not(equalTo(Version.fromString("1.7.3"))))); }