VersionHelper { public String parseVersion(final String rawVersion) { log.debug("Parsing version: " + rawVersion); String[] lines = rawVersion.split("\n"); for (String line : lines) { line = line.trim(); if (line.startsWith("install4j version ")) { String[] parts = line.split("\\s"); return parts[2]; } } throw new RuntimeException("Unable to parse version from input: " + rawVersion); } VersionHelper(final Log log); String fetchVersion(final AntHelper ant, final File install4jc); String parseVersion(final String rawVersion); void ensureVersionCompatible(final String rawVersion);  }
@Test public void parseSingleVersion() { String input = "install4j version 5.1.3 (build 5521), built on 2012-09-21"; String version = helper.parseVersion(input); assertThat(version, is("5.1.3")); }
@Test public void parseMultiLineVersion() { String input = "testing JVM in /usr …\n" + "install4j version 5.1.3 (build 5521), built on 2012-09-21\n" + "Using Java 1.8.0_25 from /Applications/install4j.app/Contents/Resources/jre.bundle/Contents/Home/jre"; String version = helper.parseVersion(input); assertThat(version, is("5.1.3")); }
@Test public void parseMultiLineCrLFVersion() { String input = "testing JVM in /usr …\r\n" + "install4j version 5.1.3 (build 5521), built on 2012-09-21"; String version = helper.parseVersion(input); assertThat(version, is("5.1.3")); }
@Test public void parseMultiLineVersionWithExtraJunk() { String input = System.currentTimeMillis() + "\n" + System.currentTimeMillis() + "\n" + System.currentTimeMillis() + "\n" + System.currentTimeMillis() + "\n" + "testing JVM in /usr …\n" + "install4j version 5.1.3 (build 5521), built on 2012-09-21"; String version = helper.parseVersion(input); assertThat(version, is("5.1.3")); }