VersionParser { static VersionNumber identifyBSDVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final Pattern pattern = Pattern.compile("\\w+bsd\\s?((\\d+)((\\.\\d+)+)?((\\-|_)[\\w\\d\\-]+)?)", Pattern.CASE_INSENSITIVE); final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX)); } return version; } 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 public void identifyBSDVersion() { final String openbsd51 = "Wget/1.13.4 (openbsd5.1)"; assertThat(VersionParser.identifyBSDVersion(openbsd51).toVersionString()).isEqualTo("5.1"); final String freebsd90 = "Wget/1.12 (freebsd9.0)"; assertThat(VersionParser.identifyBSDVersion(freebsd90).toVersionString()).isEqualTo("9.0"); final String openbsd42 = "curl/7.16.2 (i386-unknown-openbsd4.2) libcurl/7.16.2 OpenSSL/0.9.7j zlib/1.2.3 libidn/0.6.1"; assertThat(VersionParser.identifyBSDVersion(openbsd42).toVersionString()).isEqualTo("4.2"); final String freebsd49 = "curl/7.14.0 (i386-portbld-freebsd4.9) libcurl/7.14.0 OpenSSL/0.9.7b zlib/1.1.4"; assertThat(VersionParser.identifyBSDVersion(freebsd49).toVersionString()).isEqualTo("4.9"); final String freebsd82 = "Opera/9.80 (X11; FreeBSD 8.2-STABLE amd64; U; en) Presto/2.9.168 Version/11.52"; assertThat(VersionParser.identifyBSDVersion(freebsd82).toVersionString()).isEqualTo("8.2-STABLE"); final String freebsd43 = "Mozilla/5.0 (X11; U; FreeBSD 4.3-YAHOO-20010518 i386; en-US; rv:0.9) Gecko/20010719"; assertThat(VersionParser.identifyBSDVersion(freebsd43).toVersionString()).isEqualTo("4.3-YAHOO-20010518"); }