Unzipper { public Path unzipInTempDir(InputStream is, String tempDirPrefix) throws IOException { Path tempDirectory = Files.createTempDirectory(temporaryZipPath, tempDirPrefix); Path zipFile = writeInDir(is, tempDirectory); try { ZipUtil.unpack(zipFile.toFile(), tempDirectory.toFile()); } catch (org.zeroturnaround.zip.ZipException e) { throw new ZipException(e.getMessage()); } finally { FileUtils.deleteQuietly(zipFile.toFile()); } return tempDirectory; } Unzipper(); Path getTemporaryZipPath(); Path unzipInTempDir(InputStream is, String tempDirPrefix);  }
@Test(expected = ZipException.class) public void should_throw_zip_exception_when_inpustream_cannot_be_unzipped() throws Exception { InputStream stream = UnzipperTest.class.getResourceAsStream("notAzipFile.txt"); Path unzipInTempDir = unzipper.unzipInTempDir(stream, "aPrefix"); FileUtils.deleteDirectory(unzipInTempDir.toFile()); }
@Test public void should_unzip_a_zip_file_into_a_temp_folder() throws Exception { InputStream stream = UnzipperTest.class.getResourceAsStream("azipFile.zip"); Path unzipInTempDir = unzipper.unzipInTempDir(stream, "aPrefix"); assertThat(unzipInTempDir.resolve("notAzipFile.txt").toFile()).exists(); FileUtils.deleteDirectory(unzipInTempDir.toFile()); }