FileStorage implements Storage { @Override public void save(final InputStream stream) { FileOutputStream fileOutput; try { fileOutput = new FileOutputStream(configFile); try { IOUtils.copy(stream, fileOutput); } finally { fileOutput.close(); } } catch (final IOException e) { throw new RuntimeException(e); } } FileStorage();   FileStorage(final File localStorageDirectory); @Override void save(final InputStream stream); @Override InputStream load();  }
@Test(expected = NullPointerException.class) public void testEcmStoreNullFails() { final InputStream stream = null; storage.save(stream); }
@Test public void testStoreStreamCreatesNewDocument() throws Exception { final ByteArrayInputStream input = new ByteArrayInputStream("hello".getBytes()); storage.save(input); final File configFile = new File(tempDir.getRoot(), "configuration.zip"); assertTrue(configFile.exists()); assertArrayEquals("hello".getBytes(), FileUtils.readFileToByteArray(configFile)); }
@Test public void testStoreStreamUpdatesExistingDocumentAndDoesNotTryToCreateNewOne() throws Exception { final ByteArrayInputStream input = new ByteArrayInputStream("hello".getBytes()); makeConfigurationExisting("huch".getBytes()); storage.save(input); final File configFile = new File(tempDir.getRoot(), "configuration.zip"); assertTrue(configFile.exists()); assertArrayEquals("hello".getBytes(), FileUtils.readFileToByteArray(configFile)); }