FileStorageProvider implements StorageProvider { @Override public Storage read(String name) { Path path = getStorageFile(name); if (Files.notExists(path)) { throw new IllegalStateException("Storage file not found:" + 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 testReadExists() throws Exception { folder.newFile("readexists.edb"); Path expected = folder.getRoot().toPath().resolve("readexists.edb"); Storage storage = provider.read("readexists"); assertThat(storage).isInstanceOf(FileStorage.class); assertThat(((FileStorage) storage).getStorageLocation()).isEqualTo(expected); }
@Test public void testReadNotExists() { assertThatThrownBy(() -> provider.read("readnotexists")) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("readnotexists"); }