DocumentImpl implements Document, LazyLoaded<DocumentStorageService> { @Override public File toFile() throws IOException { String[] nameParts = getName().split("\\."); File file = File.createTempFile(nameParts[0], "." + nameParts[1]); file.setLastModified(getLastModified().getTime()); FileOutputStream fos = new FileOutputStream(file); fos.write(getContent()); fos.close(); return file; } DocumentImpl();  DocumentImpl(String identifier,
                        String name,
                        long size,
                        Date lastModified);  DocumentImpl(String name,
                        long size,
                        Date lastModified);  DocumentImpl(String identifier,
                        String name,
                        long size,
                        Date lastModified,
                        String link); @Override void setIdentifier(String identifier); @Override String getIdentifier(); @Override void setName(String name); @Override String getName(); @Override void setLink(String link); @Override String getLink(); @Override void setSize(long size); @Override long getSize(); @Override void setLastModified(Date lastModified); @Override Date getLastModified(); @Override String getAttribute(String attributeName); @Override void addAttribute(String attributeName,
                             String attributeValue); @Override void setAttributes(Map<String, String> attributes); @Override Map<String, String> getAttributes(); @Override void setContent(byte[] content); @Override byte[] getContent(); @Override File toFile(); @Override String toString(); @Override void setLoadService(DocumentStorageService service); @Override void load();  }
@Test public void testToFile() throws Exception { Document document = new DocumentImpl(ID, NAME, SIZE, LAST_MODIFIED, LINK); document.setContent(CONTENT.getBytes()); File file = document.toFile(); Assert.assertNotNull(file); Assert.assertNotNull(file.getName()); Assert.assertTrue(file.getName().contains(FILENAME)); Assert.assertTrue(file.getName().contains(EXTENSION)); String fileContent = new String(Files.readAllBytes(file.toPath())); Assert.assertNotNull(fileContent); Assert.assertEquals(fileContent, CONTENT); }