MavenVersionUtil { public static boolean isNewerVersion(String version1, String version2) { String v1 = Strings.emptyToNull(version1); String v2 = Strings.emptyToNull(version2); if (Objects.equal(v1, v2)) { return false; } else if (v1 == null) { return false; } else if (v2 == null) { return true; } else if (Objects.equal(VERSION_LATEST, v1)) { return true; } else if (Objects.equal(VERSION_LATEST, v2)) { return false; } String commonPrefix = Strings.commonPrefix(v1, v2); v1 = v1.substring(commonPrefix.length()); v2 = v2.substring(commonPrefix.length()); String commonSuffix = Strings.commonSuffix(v1, v2); v1 = v1.substring(0, v1.length() - commonSuffix.length()); v2 = v2.substring(0, v2.length() - commonSuffix.length()); if (v1.isEmpty()) { if (Objects.equal(VERSION_QUALIFIER_SNAPSHOT, v2.toUpperCase())) { return true; } else { return false; } } else if (Objects.equal(VERSION_QUALIFIER_SNAPSHOT, v1.toUpperCase())) { return false; } else { if (Objects.equal(VERSION_QUALIFIER_SNAPSHOT, v2.toUpperCase())) { return true; } else { return v1.compareTo(v2) > 0; } } } private  MavenVersionUtil(); static boolean isSnapshot(String version); static String calculateNextSnapshotVersion(String version, VersionUpgradeStrategy upgradeStrategy); static String calculateNextSnapshotVersion(String version); static String calculateReleaseVersion(String version); static boolean isNewerVersion(String version1, String version2); static final String VERSION_QUALIFIER_SNAPSHOT; static final String VERSION_LATEST; }
@Test @UseDataProvider("isNewerVersion") public void testIsNewerVersion(String v1, String v2, boolean expectedResult) { Assert.assertEquals(expectedResult, MavenVersionUtil.isNewerVersion(v1, v2)); }