WordTemplate implements Template<E> { @Override public void write(File file) throws IOException { OutputStream out = FileUtils.openOutputStream(file); write(out); } WordTemplate(TemplateData template, TemplateContextFactory contextFactory); @Override void toDocument(E data, OutputStream out); @Override void toTestDocument(OutputStream out); @Override void toPDFDocument(E data, OutputStream out); @Override String getDocumentName(); @Override Class<?> getInputType(); @Override Map<String, String> getProperties(); String getLanguage(); Locale getLocale(); User getLockingUser(); Date getCreatedAt(); User getEditor(); Date getEditedAt(); @Override void update(InputStream in, User editor); @Override Map<String, MappingDetail> getContentMapping(); @Override List<String> listContentIds(); @Override void validate(); @Override void write(File file); @Override void write(OutputStream out); TemplateData getTemplateData();  }
@Test public void writeTest() throws IOException { TemplateDataImpl<String> template = new TemplateDataImpl<>(); byte[] content = new byte[1]; Arrays.fill(content, Byte.MIN_VALUE); template.setContent(content); WordTemplate<?> wordTemplate = new WordTemplate<Object>(template, null); ByteArrayOutputStream out = new ByteArrayOutputStream(); wordTemplate.write(out); assertTrue("Content is not equals", Arrays.equals(content, out.toByteArray())); }
@Test public void writeFileTest() throws IOException { WordTemplate<String> template = createWordTemplate(EMPTY_WORD); File templateFile = File.createTempFile("template", "docx"); long length = templateFile.length(); try { template.write(templateFile); assertTrue("File has not been writen", templateFile.length() > length); } finally { templateFile.delete(); } }