### Question:
VersionComparator implements Comparator<String>, Serializable { @Override public int compare(final String pStr1, final String pStr2) { int result = 0; if (pStr1 == null) { if (pStr2 != null) { result = 1; } } else { if (pStr2 == null) { result = -1; } else { Matcher matcher1 = PATTERN.matcher(pStr1); Matcher matcher2 = PATTERN.matcher(pStr2); if (matcher1.matches() && matcher2.matches()) { final int major1 = Integer.parseInt(matcher1.group(VE.Major.ordinal())); final int major2 = Integer.parseInt(matcher2.group(VE.Major.ordinal())); final int minor1 = Integer.parseInt(matcher1.group(VE.Minor.ordinal())); final int minor2 = Integer.parseInt(matcher2.group(VE.Minor.ordinal())); final int micro1 = matcher1.group(VE.Micro.ordinal()) != null ? Integer.parseInt(matcher1.group( VE.Micro.ordinal())) : 0; final int micro2 = matcher2.group(VE.Micro.ordinal()) != null ? Integer.parseInt(matcher2.group( VE.Micro.ordinal())) : 0; if (major1 > major2) { result = 1; } else if (major1 < major2) { result = -1; } else { if (minor1 > minor2) { result = 1; } else if (minor1 < minor2) { result = -1; } else { if (micro1 > micro2) { result = 1; } else if (micro1 < micro2) { result = -1; } } } } else { result = pStr1.compareTo(pStr2); } } } return result; }  @Override int compare(final String pStr1, final String pStr2);  }### Answer:
@Test public void testComp() { VersionComparator testee = new VersionComparator(); Assert.assertTrue(testee.compare("6.1", "6.1.2") < 0); Assert.assertTrue(testee.compare("6.1.2", "6.1") > 0); Assert.assertTrue(testee.compare("6.2", "6.1.2") > 0); Assert.assertTrue(testee.compare("6.1.2", "6.2") < 0); Assert.assertTrue(testee.compare("6.1", "7.1") < 0); Assert.assertTrue(testee.compare("7.1", "6.1") > 0); Assert.assertTrue(testee.compare("6.1.3", "6.1.2") > 0); Assert.assertTrue(testee.compare("6.1.2", "6.1.3") < 0); Assert.assertTrue(testee.compare("6.1", "foo") < 0); Assert.assertTrue(testee.compare("foo", "6.1") > 0); Assert.assertTrue(testee.compare("foo", "FOO") > 0); Assert.assertTrue(testee.compare("FOO", "foo") < 0); Assert.assertTrue(testee.compare("6.1", null) < 0); Assert.assertTrue(testee.compare(null, "6.1") > 0); Assert.assertTrue(testee.compare(null, null) == 0); Assert.assertTrue(testee.compare("6.1.2", "6.1.2") == 0); Assert.assertTrue(testee.compare("6.1", "6.1") == 0); Assert.assertTrue(testee.compare("foo", "foo") == 0); Assert.assertTrue(testee.compare("6", "0815") > 0); Assert.assertTrue(testee.compare("6.1", "6.x") < 0); Assert.assertTrue(testee.compare("6.x", "6.1") > 0); Assert.assertTrue(testee.compare("6.1.8", "6.1.x") < 0); Assert.assertTrue(testee.compare("6.1.x", "6.1.8") > 0); }