VersionParser { public static VersionNumber parseVersion(@Nonnull final String version) { Check.notNull(version, "version"); VersionNumber result = new VersionNumber(new ArrayList<String>(0), version); final Matcher matcher = VERSIONSTRING.matcher(version); if (matcher.find()) { final List<String> groups = Arrays.asList(matcher.group(MAJOR_INDEX).split("\\.")); final String extension = matcher.group(EXTENSION_INDEX) == null ? VersionNumber.EMPTY_EXTENSION : trimRight(matcher .group(EXTENSION_INDEX)); result = new VersionNumber(groups, extension); } return result; } private  VersionParser(); static VersionNumber parseLastVersionNumber(@Nonnull final String text); static VersionNumber parseOperatingSystemVersion(@Nonnull final OperatingSystemFamily family, @Nonnull final String userAgent); static VersionNumber parseVersion(@Nonnull final String version);  }
@Test(expected = IllegalNullArgumentException.class) public void parseVersion() { VersionParser.parseVersion(null); }
@Test public void parseVersion_1() { final String version = "1"; final VersionNumber v = VersionParser.parseVersion(version); assertThat(v.toVersionString()).isEqualTo(version); }
@Test public void parseVersion_1_0_2_stable() { final String version = "1.0.2-stable"; final VersionNumber v = VersionParser.parseVersion(version); assertThat(v.toVersionString()).isEqualTo(version); }
@Test public void parseVersion_emptyString() { final VersionNumber v = VersionParser.parseVersion(""); assertThat(v).isEqualTo(VersionNumber.UNKNOWN); }
@Test public void parseVersion_leadingZero() { assertThat(VersionParser.parseVersion("3.5.07").toVersionString()).isEqualTo("3.5.07"); assertThat(VersionParser.parseVersion("10.00").toVersionString()).isEqualTo("10.00"); assertThat(VersionParser.parseVersion("5.0.0176").toVersionString()).isEqualTo("5.0.0176"); assertThat(VersionParser.parseVersion("10.00").toVersionString()).isEqualTo("10.00"); assertThat(VersionParser.parseVersion("10.00").toVersionString()).isEqualTo("10.00"); assertThat(VersionParser.parseVersion("5.01").toVersionString()).isEqualTo("5.01"); assertThat(VersionParser.parseVersion("4.01").toVersionString()).isEqualTo("4.01"); assertThat(VersionParser.parseVersion("6.02").toVersionString()).isEqualTo("6.02"); assertThat(VersionParser.parseVersion("4.01").toVersionString()).isEqualTo("4.01"); assertThat(VersionParser.parseVersion("0.016").toVersionString()).isEqualTo("0.016"); assertThat(VersionParser.parseVersion("4.01").toVersionString()).isEqualTo("4.01"); assertThat(VersionParser.parseVersion("10.00").toVersionString()).isEqualTo("10.00"); assertThat(VersionParser.parseVersion("3.5.07").toVersionString()).isEqualTo("3.5.07"); assertThat(VersionParser.parseVersion("5.05").toVersionString()).isEqualTo("5.05"); assertThat(VersionParser.parseVersion("5.01").toVersionString()).isEqualTo("5.01"); assertThat(VersionParser.parseVersion("0.002").toVersionString()).isEqualTo("0.002"); assertThat(VersionParser.parseVersion("2.60.0008").toVersionString()).isEqualTo("2.60.0008"); assertThat(VersionParser.parseVersion("4.04 [en]").toVersionString()).isEqualTo("4.04 [en]"); assertThat(VersionParser.parseVersion("4.08 [en]").toVersionString()).isEqualTo("4.08 [en]"); assertThat(VersionParser.parseVersion("7.02").toVersionString()).isEqualTo("7.02"); assertThat(VersionParser.parseVersion("11.01").toVersionString()).isEqualTo("11.01"); assertThat(VersionParser.parseVersion("7.03").toVersionString()).isEqualTo("7.03"); assertThat(VersionParser.parseVersion("10.00").toVersionString()).isEqualTo("10.00"); assertThat(VersionParser.parseVersion("11.01").toVersionString()).isEqualTo("11.01"); assertThat(VersionParser.parseVersion("11.00").toVersionString()).isEqualTo("11.00"); assertThat(VersionParser.parseVersion("6.01").toVersionString()).isEqualTo("6.01"); assertThat(VersionParser.parseVersion("9.02").toVersionString()).isEqualTo("9.02"); assertThat(VersionParser.parseVersion("0.016").toVersionString()).isEqualTo("0.016"); assertThat(VersionParser.parseVersion("0.020").toVersionString()).isEqualTo("0.020"); assertThat(VersionParser.parseVersion("3.04").toVersionString()).isEqualTo("3.04"); assertThat(VersionParser.parseVersion("5.0.0176").toVersionString()).isEqualTo("5.0.0176"); assertThat(VersionParser.parseVersion("10.00").toVersionString()).isEqualTo("10.00"); assertThat(VersionParser.parseVersion("5.01").toVersionString()).isEqualTo("5.01"); assertThat(VersionParser.parseVersion("6.00").toVersionString()).isEqualTo("6.00"); assertThat(VersionParser.parseVersion("1.00.A").toVersionString()).isEqualTo("1.00.A"); assertThat(VersionParser.parseVersion("0.06").toVersionString()).isEqualTo("0.06"); assertThat(VersionParser.parseVersion("1.01").toVersionString()).isEqualTo("1.01"); assertThat(VersionParser.parseVersion("1.00").toVersionString()).isEqualTo("1.00"); assertThat(VersionParser.parseVersion("0.01").toVersionString()).isEqualTo("0.01"); assertThat(VersionParser.parseVersion("9.00.00.3086").toVersionString()).isEqualTo("9.00.00.3086"); assertThat(VersionParser.parseVersion("9.04").toVersionString()).isEqualTo("9.04"); assertThat(VersionParser.parseVersion("9.04-beta1").toVersionString()).isEqualTo("9.04-beta1"); assertThat(VersionParser.parseVersion("6.03").toVersionString()).isEqualTo("6.03"); }
@Test public void parseVersion_minus1() { final String version = "-1"; final VersionNumber v = VersionParser.parseVersion(version); assertThat(v.getMajor()).isEqualTo(VersionNumber.EMPTY_GROUP); assertThat(v.getMinor()).isEqualTo(VersionNumber.EMPTY_GROUP); assertThat(v.getBugfix()).isEqualTo(VersionNumber.EMPTY_GROUP); assertThat(v.getExtension()).isEqualTo(version); assertThat(v.toVersionString()).isEqualTo(version); }
@Test public void parseVersion_specialChars() { final String version = "$%-"; final VersionNumber v = VersionParser.parseVersion(version); assertThat(v.getExtension()).isEqualTo(version); assertThat(v.toVersionString()).isEqualTo(version); }
@Test public void parseVersion_V() { final String version = "V"; final VersionNumber v = VersionParser.parseVersion(version); assertThat(v.getExtension()).isEqualTo(version); assertThat(v.toVersionString()).isEqualTo(version); }