JavaRuntimeUtils { static JreVersion parse() { JreVersion version = JreVersion.Unknown; String versionString = System.getProperty("java.version"); if (versionString.startsWith("1.")) { String[] versionParts = versionString.split("\\."); int featureVersion = Integer.parseInt(versionParts[1]); if (featureVersion < 7) { version = JreVersion.Unsupported; } else if (featureVersion == 7) { version = JreVersion.Java_7; } else if (featureVersion == 8) { version = JreVersion.Java_8; } else if (featureVersion == 9) { version = JreVersion.Java_9; } } else { Matcher matcher = JEP223_PATTERN.matcher(versionString); if (matcher.matches()) { int majorVersion = Integer.parseInt(matcher.group(1)); if (majorVersion == 9) { version = JreVersion.Java_9; } } } return version; }  static JreVersion getRuntimeVersion();  }
@Test public void version_unsupported() { System.setProperty("java.version", "1.6"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Unsupported, version); }
@Test public void version_java7() { System.setProperty("java.version", "1.7.22"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Java_7, version); }
@Test public void version_java8() { System.setProperty("java.version", "1.8.0_91"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Java_8, version); }
@Test public void version_java9_prerelease() { System.setProperty("java.version", "9-ea"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Java_9, version); }
@Test public void version_java9_majoronly() { System.setProperty("java.version", "9"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Java_9, version); }
@Test public void version_java9_full() { System.setProperty("java.version", "9.0.1"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Java_9, version); }
@Test public void version_java9_full_prerelease() { System.setProperty("java.version", "9.1.5-ea"); JreVersion version = JavaRuntimeUtils.parse(); assertEquals(JreVersion.Java_9, version); }