### Question:
ZipFileExtractor { public static void extractFile(final File zipFileToExtract, final File targetDir) throws ZipFileExtractionException { ZipFile zipFile = getZipFile(zipFileToExtract); if (targetDir.exists()) { try { FileUtils.deleteDirectory(targetDir); } catch (IOException e) { throw new ZipFileExtractionException("Could not delete target directory.", e); } } try { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(targetDir, entry.getName()); if (entry.isDirectory()) { entryDestination.mkdirs(); } else { entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); out.close(); } } } catch (IOException e) { throw new ZipFileExtractionException("IO Error while extracting ZIP file.", e); } finally { IOUtils.closeQuietly(zipFile); } }  static void extractFile(final File zipFileToExtract, final File targetDir);  }### Answer:
@Test void extractFile_withFileThatExists_successful() throws IOException, ZipFileExtractionException { File extractedFolder = new File(targetFolder, "aFolder"); FileUtils.deleteDirectory(extractedFolder); assertFalse(extractedFolder.exists()); ZipFileExtractor.extractFile(zipFile, targetFolder); assertAllFoldersAndFilesAreExtracted(extractedFolder); assertZipFileStillExists(zipFile); }
@Test void extractFile_withFileThatDoesNotExists_throwsException() { File zipFile = new File(currentFolder, "InexistentFile.zip"); final ZipFileExtractionException thrown = assertThrows(ZipFileExtractionException.class, () -> ZipFileExtractor.extractFile(zipFile, targetFolder)); assertTrue(thrown.getMessage().startsWith("Zip file does not exist ")); }
@Test void extractFile_andTargetFolderExistsWithExistingFile_successfulAndExistingFilesAreRemoved() throws IOException, ZipFileExtractionException { File extractedFolder = new File(targetFolder, "aFolder"); File existingFileInTargetFolder = new File(extractedFolder, "existingFile.txt"); givenTargetFolderWithExistingFile(extractedFolder, existingFileInTargetFolder); ZipFileExtractor.extractFile(zipFile, targetFolder); assertAllFoldersAndFilesAreExtracted(extractedFolder); assertZipFileStillExists(zipFile); assertFalse(existingFileInTargetFolder.exists()); }