JsonReader { private Optional<Coordinate> mapCoordinates(JsonObject object) { JsonObject objComponentIdentifier = (JsonObject) object.get("componentIdentifier"); if (objComponentIdentifier != null) { String format = (String) objComponentIdentifier.get("format"); switch (format) { case "a-name": return mapJavaScriptCoordinates((JsonObject) objComponentIdentifier.get(JSON_OBJ_COORDINATES)); case "maven": return mapMavenCoordinates((JsonObject) objComponentIdentifier.get(JSON_OBJ_COORDINATES)); case "nuget": return mapDotNetCoordinates((JsonObject) objComponentIdentifier.get(JSON_OBJ_COORDINATES)); } } return Optional.empty(); } JsonReader(Path recordingFile, Path dependencyDir, Charset encoding); List<Artifact> createArtifactsList(InputStream is);  }
@Test public void testMapCoordinates() throws URISyntaxException, IOException { Path recordFilePath = Paths.get(".", "target", "foo"); JsonReader jsonReader = new JsonReader(recordFilePath, Paths.get("tmp"), StandardCharsets.UTF_8); URI uri = this.getClass().getClassLoader().getResource("JsonReaderTest/data3.json").toURI(); InputStream iStream = Files.newInputStream(Paths.get(uri)); artifacts = jsonReader.createArtifactsList(iStream); Stream.of("pkg:maven/org.apache.commons/commons-lang3@3.5", "pkg:npm/process@0.5.1", "pkg:nuget/Microsoft.AspNetCore.SignalR@1.0.4" ).forEach(purl -> { assertThat(artifacts.stream() .map(artifact -> artifact.askFor(ArtifactCoordinates.class)) .filter(Optional::isPresent) .map(Optional::get) .anyMatch(artifactCoordinates -> artifactCoordinates.containsPurl(purl))) .isTrue(); }); }