### Question:
FullScanDataToZipOutputSupport { public void writeScanData(FullScanData data, OutputStream outputStream) throws IOException{ List<String> fileNamesAlreadyUsed = new ArrayList<>(); try (ZipOutputStream zippedOut = new ZipOutputStream(outputStream)) { for (ProjectScanLog log: data.allScanLogs) { writeStringAsZipFileEntry(zippedOut, log.toString(), "log_"+log.getUUID(),fileNamesAlreadyUsed); } for (ScanData sd: data.allScanData) { writeStringAsZipFileEntry(zippedOut, sd.result, sd.productId,fileNamesAlreadyUsed); String metaData = sd.metaData; if (metaData==null) { metaData="{ \"message\" : \"no meta data available\" }"; } writeStringAsZipFileEntry(zippedOut, metaData, "metadata_"+sd.productId,fileNamesAlreadyUsed); } zippedOut.closeEntry(); zippedOut.finish(); } }  void writeScanData(FullScanData data, OutputStream outputStream);  }### Answer:
@Test public void writeScanDataContainsDataAsExpected() throws Exception { FullScanData fullScanData = createFullScanDataTwoProductsOneLogEntry(); File file = File.createTempFile("log_fullscan", ".zip"); try(FileOutputStream fos = new FileOutputStream(file)){ supportToTest.writeScanData(fullScanData, fos ); } List<Data> list = readZipfile(file); assertEquals(5,list.size()); Data data1 = assertFile("product1.json",list); Data data2 = assertFile("product2.xml",list); Data data3 = assertFile("log_null.txt",list); Data data4 = assertFile("metadata_product1.json",list); Data data5 = assertFile("metadata_product2.json",list); assertTrue(data1.content.contains("OK")); assertTrue(data2.content.contains("NOT-OK")); assertTrue(data3.content.contains("'heavy'")); assertTrue(data4.content.contains("metadata")); assertTrue(data4.content.contains("product1")); assertTrue(data5.content.contains("metadata")); assertTrue(data5.content.contains("product2")); }
@Test public void writeScanDataWhichContainsSameProductWillIncrementFilenames() throws Exception { FullScanData fullScanData = createFullScanDataTwoProductsOneLogEntry(); FullScanData fullScanData2 = createFullScanDataTwoProductsOneLogEntry(); fullScanData.allScanData.addAll(fullScanData2.allScanData); File file = File.createTempFile("log_fullscan", ".zip"); try(FileOutputStream fos = new FileOutputStream(file)){ supportToTest.writeScanData(fullScanData, fos ); } List<Data> list = readZipfile(file); assertEquals(9,list.size()); assertFile("product1.json",list); assertFile("product1[1].json",list); assertFile("product2.xml",list); assertFile("product2[1].xml",list); assertFile("log_null.txt",list); assertFile("metadata_product1.json",list); assertFile("metadata_product1[1].json",list); assertFile("metadata_product2.json",list); assertFile("metadata_product2[1].json",list); }