### Question:
Version implements Comparable<Version> { public static Version fromRepresentation(String version) throws IllegalArgumentException { Matcher m = p.matcher(version); if(!m.matches()) { throw new IllegalArgumentException("Invalid version format, should be of the form: <major>.<minor>.<patch>.<build>-<qualifier> where <major> and <minor> are non-negative integers, <patch> and <build> are optional non-negative integers and <qualifier> may contain the letters a through z, A through Z, and the underscore character (_)."); } int major = Integer.parseInt(m.group(1)); int minor = Integer.parseInt(m.group(2)); Integer patch = m.group(3) == null ? null : Integer.parseInt(m.group(3)); Integer build = m.group(4) == null ? null : Integer.parseInt(m.group(4)); String qualifier = m.group(5); return new Version(major, minor, patch, build, qualifier, version); } Version(int major);  Version(int major, int minor);  Version(int major, int minor, @Nullable String qualifier); private  Version(int major, int minor, @Nullable String qualifier, String representation);   Version(int major, int minor, @Nullable Integer patch, @Nullable Integer build, @Nullable String qualifier, String representation); static Version fromRepresentation(String version); @Nullable static Version findNewest(Iterable<Version> versions); @Nullable static Version findNewest(Iterable<Version> versions, String qualifier); int getMajor(); int getMinor(); boolean hasQualifier(); String getQualifier(); String getRepresentation(); boolean hasPatch(); Integer getPatch(); boolean hasBuild(); Integer getBuild(); @Override int compareTo(Version o); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Version UNVERSIONED; }### Answer:
@Test public void testSort() { List<Version> input = Arrays.asList( Version.fromRepresentation("1.0-alpha"), Version.fromRepresentation("1.0-beta"), Version.fromRepresentation("1.0"), Version.fromRepresentation("1.1-gamma"), Version.fromRepresentation("1.1"), Version.fromRepresentation("1.2"), Version.fromRepresentation("2.104") ); List<Version> expected = new ArrayList<>(input); Collections.reverse(expected); List<Version> actual = new ArrayList<>(input); Collections.sort(actual); assertEquals(expected, actual); }