@Test public void will_fail_if_unable_to_create_the_parent_directory() throws IOException { Path parent = Files.createFile(baseDir.resolve("not-a-directory")); thrown.expect(FileAlreadyExistsException.class); UniqueDirectories.createUniqueDir(parent, 123); }
public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } } }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }  }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }  static Path createUniqueDir(Path parentDir, long sequence); }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }  static Path createUniqueDir(Path parentDir, long sequence);  }