VersionUtils { public static String completeIncremental(String version) throws ValidationException { Semver semver = new Semver(version, LOOSE); Optional<Integer> minor = Optional.ofNullable(semver.getMinor()); Optional<Integer> patch = Optional.ofNullable(semver.getPatch()); if (!minor.isPresent() || !patch.isPresent()) { version = create(semver.getMajor(), minor.orElse(0), patch.orElse(0)).toString(); } if (!isVersionValid(version)) { throw new ValidationException("Version is invalid: " + version); } return getBaseVersion(version); }  static Boolean isVersionValid(String version); static Boolean isVersionGreaterOrEquals(String version1, String version2); static String completeIncremental(String version); static String getBaseVersion(String version); static String getMajor(String version); static boolean isRange(String version);  }
@Test public void completeIncrementalString() throws ValidationException { String version = "3.3"; assertThat(completeIncremental(version), is(version + ".0")); }
@Test public void completeIncrementalStringWithQualifier() throws ValidationException { String version = "3.3"; String qualifier = "-SNAPSHOT"; assertThat(completeIncremental(version + qualifier), is(version + ".0")); }
@Test public void completeIncrementalStringNoChanges() throws ValidationException { String version = "3.3.2"; assertThat(completeIncremental(version), is(version)); }
@Test public void completeIncrementalStringNoChangesWithQualifier() throws ValidationException { String version = "3.3.2"; String qualifier = "-SNAPSHOT"; assertThat(completeIncremental(version + qualifier), is(version)); }
@Test public void completeIncrementalTest() throws ValidationException { Map<String, String> testInput = completeIncrementalTestInput(); for (String version : testInput.keySet()) { String expectedVersion = testInput.get(version); assertThat("Completed version is not the expected", completeIncremental(version), equalTo(expectedVersion)); } }