AnonymousOdsFileWriter { public void saveAs(final String filename) throws IOException { this.saveAs(new File(filename)); } AnonymousOdsFileWriter(final Logger logger, final AnonymousOdsDocument document); OdsDocument document(); void save(final OutputStream out); @Deprecated void save(final OutputStream out, final ZipUTF8WriterBuilderImpl builder); void save(final ZipUTF8Writer writer); void saveAs(final String filename); void saveAs(final File file); void saveAs(final String filename, final ZipUTF8WriterBuilder builder); void saveAs(final File file, final ZipUTF8WriterBuilder builder);  }
@Test(expected = IOException.class) public final void testFileIsDir() throws IOException { final Logger l = PowerMock.createNiceMock(Logger.class); final OdsFactory of = OdsFactory.create(l, Locale.US); PowerMock.resetAll(); TestHelper.initMockDocument(this.odsElements); PowerMock.replayAll(); of.createWriter().saveAs("."); PowerMock.verifyAll(); }
@Test(expected = IOException.class) public final void testSaveAsNullFile() throws IOException { PowerMock.resetAll(); TestHelper.initMockDocument(this.odsElements); PowerMock.replayAll(); final AnonymousOdsDocument document = this.getAnonymousDocument(); new AnonymousOdsFileWriter(this.logger, document).saveAs((File) null); PowerMock.verifyAll(); }
@Test public final void testSaveWithWriter() throws IOException { final OutputStream outputStream = PowerMock.createMock(OutputStream.class); final ZipUTF8Writer z = PowerMock.createMock(ZipUTF8Writer.class); final File temp = File.createTempFile("temp-fastods", ".tmp"); PowerMock.resetAll(); TestHelper.initMockDocument(this.odsElements); EasyMock.expect(this.builder.build(EasyMock.isA(FileOutputStream.class))).andReturn(z); this.odsElements .createEmptyElements(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); this.odsElements .writeMimeType(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); this.odsElements.writeMeta(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); this.odsElements.writeStyles(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); this.odsElements.writeContent(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); this.odsElements .writeSettings(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); this.odsElements.writeExtras(EasyMock.eq(this.xmlUtil), EasyMock.isA(ZipUTF8Writer.class)); outputStream.write(EasyMock.isA(byte[].class), EasyMock.anyInt(), EasyMock.anyInt()); EasyMock.expectLastCall().anyTimes(); outputStream.flush(); EasyMock.expectLastCall().anyTimes(); z.finish(); z.close(); PowerMock.replayAll(); final AnonymousOdsDocument document = this.getAnonymousDocument(); new AnonymousOdsFileWriter(this.logger, document).saveAs(temp, this.builder); PowerMock.verifyAll(); }
@Test(expected = IOException.class) public final void testSaveWithWriterDir() throws IOException { PowerMock.resetAll(); TestHelper.initMockDocument(this.odsElements); PowerMock.replayAll(); final AnonymousOdsDocument document = this.getAnonymousDocument(); new AnonymousOdsFileWriter(this.logger, document).saveAs(".", this.builder); PowerMock.verifyAll(); }