### Question:
DataFile implements Serializable { public void saveAs(OutputStream out) throws IOException { out.write(getBytes()); out.close(); } DataFile(String path, String mimeType);  DataFile(byte[] data, String fileName, String mimeType);  DataFile(InputStream stream, String fileName, String mimeType); protected  DataFile(DSSDocument document);  DataFile(); byte[] calculateDigest(); byte[] calculateDigest(URL method); byte[] calculateDigest(org.digidoc4j.DigestAlgorithm digestType); String getName(); String getId(); long getFileSize(); String getMediaType(); void setMediaType(String mediaType); void saveAs(OutputStream out); void saveAs(String path); byte[] getBytes(); InputStream getStream(); void setId(String dataFileId); DSSDocument getDocument(); void setDocument(DSSDocument document);  }### Answer:
@Test public void testSaveToFile() throws IOException { String file = this.getFileBy("txt"); this.dataFile.saveAs(file); Assert.assertTrue(new File(file).exists()); byte[] testFileContent = FileUtils.readFileToByteArray(new File("src/test/resources/testFiles/helper-files/test.txt")); byte[] savedFileContent = FileUtils.readFileToByteArray(new File(file)); Assert.assertArrayEquals(testFileContent, savedFileContent); }
@Test public void testSaveToOutputStream() throws IOException { try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { this.dataFile.saveAs(stream); stream.flush(); Assert.assertEquals("see on testfail", stream.toString()); } }