FileSystemArchiveFile extends ArchiveFile { public InputStream toStream() throws IOException { File archiveFile = new File(generateFilePath()); checkMd5Of(archiveFile); return new FileInputStream(archiveFile); } FileSystemArchiveFile(String mimeType, String originalFixity, String fileName, String filesDirectory); InputStream toStream(); File copyStreamToDirectory(String directory); String generateFilePath();  }
@Test(expected = RuntimeException.class) public void test_exception_thrown_on_bad_fixity() throws IOException { FileSystemArchiveFile af = new FileSystemArchiveFile("mime", "badFixity", FILE_NAME, TEST_DIRECTORY); af.toStream(); }
@Test public void test_that_toStream_returns_contents_of_file() throws IOException { String fullPath = TEST_DIRECTORY + "/" + FILE_NAME; File preArchiveFile = new File(fullPath); String originalMd5; try { originalMd5 = FixityUtils.calculateMD5(preArchiveFile); } catch (FileNotFoundException fnfe) { throw new RuntimeException("FileNotFoundException thrown by MD5 fixity utility.", fnfe); } InputStream is = null; try { FileSystemArchiveFile af = new FileSystemArchiveFile("mime", originalMd5, FILE_NAME, TEST_DIRECTORY); is = af.toStream(); String valueFromStream = buildStringFromStream(is); assertThat(valueFromStream, containsString("<string name=\"settings-directory\">settings</string>")); } finally { is.close(); } }