@Test public void testFailures() { try { PomVersion.parse("1.2"); fail("should throw"); } catch (RuntimeException e) { assertTrue("should contain something about format", e.getMessage().contains("format")); } try { PomVersion.parse("1.2.3.4"); fail("should throw"); } catch (RuntimeException e) { assertTrue("should contain something about format", e.getMessage().contains("format")); } try { PomVersion.parse("x.y.z"); fail("should throw"); } catch (RuntimeException e) { assertTrue("should contain something about must be numbers", e.getMessage().contains("number")); } }
public static PomVersion parse(final String str) { boolean isSnapshot = false; String version = str; if (str.endsWith("-SNAPSHOT")) { isSnapshot = true; version = version.substring(0, str.length() - 9); } final Iterable<String> bits = Splitter.on(".").split(version); if (size(bits) != 3) { throw new RuntimeException("Version string format is invalid"); } try { final Integer newMajor = Integer.valueOf(get(bits, 0)); final Integer newMinor = Integer.valueOf(get(bits, 1)); final Integer newPatch = Integer.valueOf(get(bits, 2)); return new PomVersion(isSnapshot, newMajor, newMinor, newPatch); } catch (NumberFormatException e) { throw new RuntimeException("Version portions are not numbers! " + str, e); } }
PomVersion implements Comparable<PomVersion> { public static PomVersion parse(final String str) { boolean isSnapshot = false; String version = str; if (str.endsWith("-SNAPSHOT")) { isSnapshot = true; version = version.substring(0, str.length() - 9); } final Iterable<String> bits = Splitter.on(".").split(version); if (size(bits) != 3) { throw new RuntimeException("Version string format is invalid"); } try { final Integer newMajor = Integer.valueOf(get(bits, 0)); final Integer newMinor = Integer.valueOf(get(bits, 1)); final Integer newPatch = Integer.valueOf(get(bits, 2)); return new PomVersion(isSnapshot, newMajor, newMinor, newPatch); } catch (NumberFormatException e) { throw new RuntimeException("Version portions are not numbers! " + str, e); } } }
PomVersion implements Comparable<PomVersion> { public static PomVersion parse(final String str) { boolean isSnapshot = false; String version = str; if (str.endsWith("-SNAPSHOT")) { isSnapshot = true; version = version.substring(0, str.length() - 9); } final Iterable<String> bits = Splitter.on(".").split(version); if (size(bits) != 3) { throw new RuntimeException("Version string format is invalid"); } try { final Integer newMajor = Integer.valueOf(get(bits, 0)); final Integer newMinor = Integer.valueOf(get(bits, 1)); final Integer newPatch = Integer.valueOf(get(bits, 2)); return new PomVersion(isSnapshot, newMajor, newMinor, newPatch); } catch (NumberFormatException e) { throw new RuntimeException("Version portions are not numbers! " + str, e); } } PomVersion(@JsonProperty("snapshot") boolean isSnapshot,
                    @JsonProperty("major") int major,
                    @JsonProperty("minor") int minor,
                    @JsonProperty("patch") int patch); }
PomVersion implements Comparable<PomVersion> { public static PomVersion parse(final String str) { boolean isSnapshot = false; String version = str; if (str.endsWith("-SNAPSHOT")) { isSnapshot = true; version = version.substring(0, str.length() - 9); } final Iterable<String> bits = Splitter.on(".").split(version); if (size(bits) != 3) { throw new RuntimeException("Version string format is invalid"); } try { final Integer newMajor = Integer.valueOf(get(bits, 0)); final Integer newMinor = Integer.valueOf(get(bits, 1)); final Integer newPatch = Integer.valueOf(get(bits, 2)); return new PomVersion(isSnapshot, newMajor, newMinor, newPatch); } catch (NumberFormatException e) { throw new RuntimeException("Version portions are not numbers! " + str, e); } } PomVersion(@JsonProperty("snapshot") boolean isSnapshot,
                    @JsonProperty("major") int major,
                    @JsonProperty("minor") int minor,
                    @JsonProperty("patch") int patch); boolean isSnapshot(); int getMajor(); int getMinor(); int getPatch(); @Override String toString(); static PomVersion parse(final String str); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(@NotNull PomVersion pv); }
PomVersion implements Comparable<PomVersion> { public static PomVersion parse(final String str) { boolean isSnapshot = false; String version = str; if (str.endsWith("-SNAPSHOT")) { isSnapshot = true; version = version.substring(0, str.length() - 9); } final Iterable<String> bits = Splitter.on(".").split(version); if (size(bits) != 3) { throw new RuntimeException("Version string format is invalid"); } try { final Integer newMajor = Integer.valueOf(get(bits, 0)); final Integer newMinor = Integer.valueOf(get(bits, 1)); final Integer newPatch = Integer.valueOf(get(bits, 2)); return new PomVersion(isSnapshot, newMajor, newMinor, newPatch); } catch (NumberFormatException e) { throw new RuntimeException("Version portions are not numbers! " + str, e); } } PomVersion(@JsonProperty("snapshot") boolean isSnapshot,
                    @JsonProperty("major") int major,
                    @JsonProperty("minor") int minor,
                    @JsonProperty("patch") int patch); boolean isSnapshot(); int getMajor(); int getMinor(); int getPatch(); @Override String toString(); static PomVersion parse(final String str); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(@NotNull PomVersion pv);  }