### Question:
FileUtil { public static File getExistingDirectory(String directory, String toolHome) { final File dir = getFile(directory, toolHome); if (dir != null) { if (!dir.isDirectory()) { final String message = String.format("Directory '%s': is not existing", dir); throw new ToolException(message, ToolException.TOOL_IO_ERROR); } if (!dir.canWrite()) { final String message = String.format("Directory '%s': is not writable", dir); throw new ToolException(message, ToolException.TOOL_IO_ERROR); } } return dir; }  static File getExistingFile(String path, String toolHome); static File getExistingDirectory(String directory, String toolHome);  }### Answer:
@Test public void testGetExistingDirectory_notExisting() { final File toolHomeFile = new File("."); final String toolHome = toolHomeFile.getAbsolutePath(); try { FileUtil.getExistingDirectory("not_there", toolHome); fail("ToolException expected"); } catch (ToolException expected) { } }
@Test public void testGetExistingDirectory_existing() throws IOException { final File toolHomeFile = new File("."); final String toolHome = toolHomeFile.getAbsolutePath(); final File existingFile = new File(toolHome, "delete_me"); if (!existingFile.mkdir()) { fail("failed to create test directory"); } try { final File file = FileUtil.getExistingDirectory(existingFile.getAbsolutePath(), toolHome); assertNotNull(file); assertEquals(existingFile.getAbsolutePath(), file.getAbsolutePath()); } finally { if (!existingFile.delete()) { fail("failed to delete test directory"); } } }