FileBasedFilesystemDirectory implements FilesystemDirectory { @Override public FileData create(String filename, boolean canExist) throws IOException { Path path = directory.resolve(filename); StandardOpenOption createOption = canExist ? CREATE : CREATE_NEW; FileChannel channel = FileChannel.open(path, READ, WRITE, createOption); return new FileChannelFileData(channel); } FileBasedFilesystemDirectory(Path directory); @Override DirectoryLock lock(); @Override FileData create(String filename, boolean canExist); @Override FileData getFileData(String filename); @Override void delete(String filename); @Override void backup(String filename);  }
@Test public void createNotExistsButCan() throws Exception { filesystemDirectory.create("abc", true).close(); assertTrue(Files.exists(testPath.resolve("abc"))); }
@Test public void createNotExistsAndCannot() throws Exception { filesystemDirectory.create("abc", false).close(); assertTrue(Files.exists(testPath.resolve("abc"))); }
@Test public void createExistsAndCan() throws Exception { filesystemDirectory.create("abc", true).close(); filesystemDirectory.create("abc", true).close(); assertTrue(Files.exists(testPath.resolve("abc"))); }
@Test(expected = IOException.class) public void createExistsAndCannot() throws Exception { filesystemDirectory.create("abc", true).close(); filesystemDirectory.create("abc", false); }