### Question:
ZipHelper { public static void zip(File file, OutputStream output) throws IOException { zip(file, output, false); }  static void zip(File file, OutputStream output); static void zip(File file, OutputStream output, boolean includeRoot);  }### Answer:
@Test public void shouldZipSingleFile() throws Exception { final File file = temporaryFolder.resolve(SOME_FILE).toFile(); file.createNewFile(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipHelper.zip(file, output); output.close(); verifyZipContent(output, SOME_FILE); } }
@Test public void shouldZipDir() throws Exception { Path toZipDir = temporaryFolder.resolve("toZip"); toZipDir.toFile().mkdirs(); File toZipFile = toZipDir.resolve(SOME_FILE_PATH).toFile(); toZipFile.getParentFile().mkdirs(); toZipFile.createNewFile(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipHelper.zip(toZipDir.toFile(), output, true); output.close(); verifyZipContent(output, Paths.get("toZip", "a", "b", SOME_FILE).toString()); } }
@Test public void shouldZipDirWithoutRoot() throws Exception { Path toZipDir = temporaryFolder.resolve("toZip"); toZipDir.toFile().mkdirs(); File toZipFile = toZipDir.resolve(SOME_FILE_PATH).toFile(); toZipFile.getParentFile().mkdirs(); toZipFile.createNewFile(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipHelper.zip(toZipDir.toFile(), output); output.close(); verifyZipContent(output, Paths.get("a", "b", SOME_FILE).toString()); } }
@Test public void shouldNotZipAlreadyZipped() throws Exception { final File file = temporaryFolder.resolve(SOME_FILE).toFile(); file.createNewFile(); final File zipped = temporaryFolder.resolve("zipped.zip").toFile(); try (FileOutputStream zipStream = new FileOutputStream(zipped)) { ZipHelper.zip(file, zipStream); zipStream.close(); } try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipHelper.zip(zipped, output); output.close(); verifyZipContent(output, SOME_FILE); } }