FileStorageProvider implements StorageProvider { @Override public Storage create(String name) throws StorageExistsException { Path path = getStorageFile(name); if (Files.exists(path)) { throw new StorageExistsException("Storage file already exists: " + path.toAbsolutePath()); } return new FileStorage(path); } FileStorageProvider(Path storageDirectory); @Override Storage create(String name); @Override Storage read(String name); @Override boolean exists(String name);  }
@Test public void testCreateNotExists() throws Exception { Path expected = folder.getRoot().toPath().resolve("createnotexists.edb"); Storage storage = provider.create("createnotexists"); assertThat(storage).isInstanceOf(FileStorage.class); assertThat(((FileStorage) storage).getStorageLocation()).isEqualTo(expected); assertThat(expected).doesNotExist(); }
@Test public void testCreateExists() throws Exception { folder.newFile("createexists.edb"); assertThatThrownBy(() -> provider.create("createexists")) .isInstanceOf(StorageExistsException.class) .hasMessageContaining("createexists"); }