CopyContentIfNotExistsVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path target = targetDirectory.resolve(srcDirectory.relativize(dir)); if (!exists(target)) { createDirectory(target); } return FileVisitResult.CONTINUE; } CopyContentIfNotExistsVisitor(Path srcDirectory, Path targetDirectory); @Override FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs); @Override FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs);  }
@Test public void should_create_given_directory() throws Exception { visitor.preVisitDirectory(source.toPath().resolve("widgets"), null); assertThat(exists(destination.toPath().resolve("widgets"))).isTrue(); }
@Test public void should_not_create_given_directory_if_it_already_exist() throws Exception { createDirectories(destination.toPath().resolve("widgets")); visitor.preVisitDirectory(source.toPath().resolve("widgets"), null); assertThat(exists(destination.toPath().resolve("widgets"))).isTrue(); }