### Question:
ZipFileUtil { public static void unzipToDir(File zipFile, File destDir) throws IOException { log.debug("Unzipping to directory: " + destDir.getPath()); unzip(new FileInputStream(zipFile), destDir); } private  ZipFileUtil(); static File unzipToTemp(File zipFile); static File unzipToTemp(InputStream zipStream); static void unzipToDir(File zipFile, File destDir); static void unzip(InputStream is, File destDir);  }### Answer:
@Test public void testUnzipRelativePathsOutsideDir() throws IOException { File zipFile; ClassPathResource resource = new ClassPathResource("/samples/bad-zip-with-relative-path.zip"); zipFile = resource.getFile(); File tempDir = File.createTempFile("test", null); tempDir.delete(); tempDir.mkdir(); tempDir.deleteOnExit(); try { ZipFileUtil.unzipToDir(zipFile, tempDir); fail("Expected IOException to be thrown"); } catch (IOException e) { } }
@Test public void testUnzipInsideDir() throws IOException { File zipFile; ClassPathResource resource = new ClassPathResource("/samples/test-mets-zip.zip"); zipFile = resource.getFile(); File tempDir = File.createTempFile("test", null); tempDir.delete(); tempDir.mkdir(); tempDir.deleteOnExit(); try { ZipFileUtil.unzipToDir(zipFile, tempDir); } catch (IOException e) { fail("Expected IOException to not be thrown"); } }