FileStorage extends StorageSupport { @Override protected void initialize() throws StorageExistsException { try { Files.createFile(location); } catch (FileAlreadyExistsException exc) { throw new StorageExistsException("Storage already exists: " + exc.getMessage()); } catch (IOException e) { throw new UncheckedIOException(e); } } FileStorage(Path location); @Override String getReference(); @Override void append(String data); @Override Stream<String> read(Charset charset);  }
@Test public void createsTheStorageFile() throws Exception { assertThat(this.storageFile).doesNotExist(); this.fileStorage.initialize(); assertThat(this.storageFile).exists(); }
@Test public void throwsExceptionWhenStorageFileExists() throws Exception { Files.write(storageFile, Arrays.asList("Hello, I exist")); assertThatThrownBy(() -> this.fileStorage.initialize()) .isInstanceOf(StorageExistsException.class); }