NodeInfoReader implements BuildInfoReader { protected static String getVersionFromOutput(String output) { if (Strings.isNullOrEmpty(output)) { throw new IllegalArgumentException("nodejs version output should not be empty!"); } return Arrays.stream(output.split(NEW_LINE)) .filter(l -> l.contains("npm")) .map(NodeInfoReader::readValue) .findFirst() .orElseThrow( () -> new IllegalStateException("Unknown nodejs version output format. Expected at least one line!")); }  @Override int order(); @Override boolean isApplicable(Path root); @Override BuildInfo getInfo(Path root); static String getVersion(Path modulePath); static final String NEW_LINE; }
@Test public void shouldReturnNpmVersionFromOutput() throws Exception { try (InputStream is = NodeInfoReader.class.getClassLoader().getResourceAsStream("npm/npm-version-output.json")) { String out = Strings.read(is); String result = NodeInfoReader.getVersionFromOutput(out); assertEquals("6.14.5", result); } }