Version implements Comparable<Version> { @Override public String toString() { StringBuilder msg = new StringBuilder(); msg.append(this.major).append('.').append(this.minor); if (this.point > 0) { msg.append('.').append(this.point); } return msg.toString(); } Version(int maj, int minor);  Version(int maj, int minor, int point);  Version(String ver); @Override int compareTo(Version o); @Override boolean equals(Object obj); int getMajor(); int getMinor(); int getPoint(); @Override int hashCode(); @Override String toString();  }
@Test public void testVersionComparable() { String unsorted[] = { "1.5", "2.3.1", "1.0", "2.2", "2.3" }; String expected[] = { "2.3.1", "2.3", "2.2", "1.5", "1.0" }; List<Version> versions = new ArrayList<Version>(); for (String u : unsorted) { versions.add(new Version(u)); } System.out.printf("Unsorted: %s%n", versions); Collections.sort(versions); System.out.printf("Sorted: %s%n", versions); int len = expected.length; Assert.assertEquals("Expected.length", expected.length, versions.size()); for (int i = 0; i < len; i++) { Assert.assertEquals("Expected[" + i + "]", expected[i], versions.get(i).toString()); } }