FileUtil { public static void deleteFolder(final String path) throws IOException { final Path directory = Paths.get(path); deleteFolder(directory); } private  FileUtil(); static void deleteFolder(final String path); static void ensureDirectoryExists(final Path directory); static void deleteFolder(final Path directory); @SuppressWarnings("resource") static FileChannel openChannel(final String filename, final boolean create); static void replace(final Path src, final Path dest); static void deleteFile(final File file); static void copySnapshot(final Path runtimeDirectory, final Path snapshotDirectory); static final Logger LOG; }
@Test public void shouldThrowExceptionForNonExistingFolder() { final File root = tempFolder.getRoot(); tempFolder.delete(); assertThatThrownBy( () -> { FileUtil.deleteFolder(root.getAbsolutePath()); }) .isInstanceOf(NoSuchFileException.class); }
@Test public void shouldDeleteFolder() throws IOException { final File root = tempFolder.getRoot(); tempFolder.newFile("file1"); tempFolder.newFile("file2"); tempFolder.newFolder("testFolder"); FileUtil.deleteFolder(root.getAbsolutePath()); assertThat(root.exists()).isFalse(); }