### Question:
Version implements Comparable<Version> { @Override public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(major); if (minor >= 0) { buffer.append(".").append(minor); if (patch >= 0) buffer.append(".").append(patch); } if (qualifier.length() != 0) { buffer.append("-").append(qualifier); if (build >= 0) buffer.append("-").append(build); } return buffer.toString(); } Version(String versionStr);  Version(int major, int minor, int patch, String qualifier, int build);  Version(int major, int minor, int patch);  Version(int major, int minor);  Version(int major); int getMajor(); int getMinor(); int getPatch(); String getQualifier(); int getBuild(); boolean isCompatible(Version version); @Override int compareTo(Version version); @Override String toString();  }### Answer:
@Test public void shouldConstructVersionCorrectly() { Version version = new Version(1, 2, 3, "beta", 100); assertEquals(version.toString(), "1.2.3-beta-100"); version = new Version(1, 2, -1, "beta", -1); assertEquals(version.toString(), "1.2-beta"); try { version = new Version(-1, 2, 1, "build", 1); fail("Can not detect construction errors."); } catch (Exception e) { } try { version = new Version(1, 2, -1, null, 1); fail("Can not detect construction errors."); } catch (Exception e) { } try { version = new Version(1, -1, 0, null, -1); fail("Can not detect construction errors."); } catch (Exception e) { } }
@Test public void shouldDecodeVersionStringCorrectly() { Version version = new Version("1.2.3-build-100"); assertEquals(version.toString(), "1.2.3-build-100"); version = new Version("1.2-100"); assertEquals(version.toString(), "1.2-100"); version = new Version("1-build-10"); assertEquals(version.toString(), "1-build-10"); }