JsonReader { @SuppressWarnings("WeakerAccess") protected List<Artifact> createArtifactsList(InputStream stream, List<String> filterStrings) { LOGGER.debug("Create artifacts list from input stream."); List<Artifact> artifacts = new ArrayList<>(); List<JsonObject> objects = readJsonObjects(stream); for (JsonObject obj : objects) { if (filterObject(obj, Optional.ofNullable(filterStrings))) { continue; } Artifact artifact = mapArtifact(obj); artifacts.add(artifact); } LOGGER.debug("Creation of artifacts list finished."); try { stream.close(); } catch (IOException e) { LOGGER.debug("Failed to close stream. Ignored."); } return artifacts; } JsonReader(Path recordingFile, Path dependencyDir, Charset encoding); List<Artifact> createArtifactsList(InputStream is);  }
@Test public void testMappingAdditionalInformationForLicenses() 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/data.json").toURI(); InputStream iStream = Files.newInputStream(Paths.get(uri)); artifacts = jsonReader.createArtifactsList(iStream); assertThat(artifacts.get(0).askForGet(ObservedLicenseInformation.class)).isEmpty(); assertThat(artifacts.get(0).askFor(MissingLicenseInformation.class).get().getMissingLicenseReasons()) .containsExactlyInAnyOrder(MissingLicenseReasons.NO_LICENSE_IN_SOURCES); }
@Test public void testParseData2() 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/data2.json").toURI(); InputStream iStream = Files.newInputStream(Paths.get(uri)); artifacts = jsonReader.createArtifactsList(iStream); assertThat(artifacts.stream() .map(artifact -> artifact.askForGet(DeclaredLicenseInformation.class)) .filter(Optional::isPresent) .map(Optional::get) .map(LicenseInformation::evaluate)) .contains("PUBLIC-DOMAIN"); assertThat(artifacts.stream() .map(Artifact::getAnalysisSource)).contains("JSON"); Optional<List<Issue>> issues = artifacts.stream() .map(artifact -> artifact.askForGet(ArtifactIssues.class)) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); assertThat(issues.isPresent()).isTrue(); issues.ifPresent(i -> { assertThat(i.stream().map(Issue::getStatus)).contains(SecurityIssueStatus.OPEN); assertThat(i.stream().map(Issue::getReference)).contains("CVE-2018-8014"); assertThat(i.stream().map(Issue::getSeverity)).contains(5.9); }); }