### Question:
SafeFiles { public static void ensureDirectoryExists(final Path path) throws IOException { if (Files.exists(path)) { if (!Files.isDirectory(path)) { throw new IOException("path is not a directory: " + path); } } else { Files.createDirectories(path); fsyncLineage(path.getParent()); } } private  SafeFiles(); static void rename(final Path oldName, final Path newName); static void ensureDirectoryExists(final Path path); @Nonnegative static int fsyncRecursive(final Path root); static void fsync(final Path path); static void writeUTF8(final String value, final Path path); static void write(final byte[] data, final Path path); @Nonnull static SafeOutputStream createAtomicFile(final Path path); static void deleteIfExistsQuietly(final Path path);  }### Answer:
@Test public void ensureDirectoryExists() throws IOException { final Path path = root.resolve("dir"); Assert.assertFalse(java.nio.file.Files.exists(path)); SafeFiles.ensureDirectoryExists(path); Assert.assertTrue(java.nio.file.Files.exists(path)); SafeFiles.ensureDirectoryExists(path); Assert.assertTrue(java.nio.file.Files.exists(path)); }