public static void deleteDirectory(File file) {
        Path pathToBeDeleted = file.toPath();
        try {
            Files.walk(pathToBeDeleted)
                    .sorted(Comparator.reverseOrder())
                    .map(Path::toFile)
                    .forEach(File::delete);
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
@Test
    void testDeleteDirectory() throws Exception {
        new File("target/foo/bar").mkdirs();
        FileUtils.writeToFile(new File("target/foo/hello.txt"), "hello world");
        FileUtils.writeToFile(new File("target/foo/bar/world.txt"), "hello again");
        assertTrue(new File("target/foo/hello.txt").exists());
        assertTrue(new File("target/foo/bar/world.txt").exists());
        FileUtils.deleteDirectory(new File("target/foo"));
        assertFalse(new File("target/foo/hello.txt").exists());
        assertFalse(new File("target/foo/bar/world.txt").exists());        
    }