ClearingReportGenerator { Path createClearingDocument(SW360Release release, Path targetDir) { Path clearingDocument = targetDir.resolve(release.getId() + CLEARING_DOC_SUFFIX); try { Files.createDirectories(targetDir); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(Files.newBufferedWriter(clearingDocument), release); return clearingDocument; } catch (IOException e) { throw new SW360ClientException("Could not create clearing document " + clearingDocument.toString(), e); } }    }
@Test public void createClearingDocument() throws IOException { File targetFolder = folder.newFolder(); SW360Release release = SW360TestUtils.mkSW360Release("testRelease"); release.setOverriddenLicense("overridden"); Path clearingDocument = generator.createClearingDocument(release, targetFolder.toPath()); assertThat(Files.exists(clearingDocument)).isTrue(); assertThat(clearingDocument.getFileName().toString()).isEqualTo(release.getId() + "_clearing.json"); ObjectMapper mapper = new ObjectMapper(); mapper.readValue(clearingDocument.toFile(), SW360Release.class); String content = String.join("", Files.readAllLines(clearingDocument)); assertThat(content).contains(release.getDeclaredLicense()); assertThat(content).contains(release.getObservedLicense()); assertThat(content).contains(release.getOverriddenLicense()); System.out.println(content); }
@Test public void testMissingFolderIsCreated() throws IOException { Path root = folder.newFolder().toPath(); Path nonExistingFolder = root.resolve("non/existing/folder"); SW360Release release = SW360TestUtils.mkSW360Release("create"); Path clearingDocument = generator.createClearingDocument(release, nonExistingFolder); assertThat(Files.exists(clearingDocument)).isTrue(); }