  @Test
  public void testRemoveRecursive() throws Exception {

    final Path root = Files.createDirectory(fs.getPath("/", "root"));
    final Path unrelated = Files.write(root.resolve("unrelated"), new byte[] {0x0f});

    final Path dir = Files.createDirectory(root.resolve("dir"));
    Files.write(dir.resolve("a"), new byte[] {0x00});
    Files.write(dir.resolve("b"), new byte[] {0x01});
    Files.createSymbolicLink(dir.resolve("c"), dir.resolve("b"));
    // The target of this link intentionally points to a file outside of our dir
    Files.createSymbolicLink(dir.resolve("d"), unrelated);
    // Create a subdir
    final Path subdir = Files.createDirectory(dir.resolve("subdir"));
    Files.write(subdir.resolve("e"), new byte[] {0x00});
    Files.write(subdir.resolve("f"), new byte[] {0x01});

    PathUtils.removeRecursive(dir);

    assertThat(Files.notExists(dir), describedAs("directory was deleted", is(true)));
    assertThat(Files.exists(unrelated), describedAs("unrelated file was kept", is(true)));
  }