DocxWriter { public void export() throws DocxWriterException { if (!checkDirectory(workingDirectory)) { throw new DocxWriterException("Working directory could not be checked"); } if (!checkFile(exportFile)) { throw new DocxWriterException("Export File could not be checked"); } if (exporter == null) { throw new DocxWriterException("Exporter could not be null"); } try { exporter.compile(workingDirectory); } catch (DocxExporterException e) { throw new DocxWriterException("Failed to compile exporter", e); } final String rootPath = FilenameUtils.normalize(workingDirectory.getPath() + "/"); ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(exportFile)); zipDirectory(rootPath, workingDirectory, zos); } catch (IOException e) { throw new DocxWriterException("Failed to zip template directory", e); } finally { FileUtils.closeQuietly(zos); } }  void export();  }
@Test(expected = DocxWriterException.class) public void export_With_NullWorkingDirectory_Should_Throw_DocxWriterException() throws DocxWriterException { workingDirectory = null; DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_NullExportFile_Should_Throw_DocxWriterException() throws DocxWriterException { exportFile = null; DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_NullExporter_Should_Throw_DocxWriterException() throws DocxWriterException { exporter = null; DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_NonExisting_WorkingDirectory_Should_Throw_DocxWriterException() throws DocxWriterException { workingDirectory = Mockito.mock(File.class); Mockito.when(workingDirectory.exists()).thenReturn(false); DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_Non_Writeable_WorkingDirectory_Should_Throw_DocxWriterException() throws DocxWriterException { workingDirectory = Mockito.mock(File.class); Mockito.when(workingDirectory.exists()).thenReturn(true); Mockito.when(workingDirectory.canWrite()).thenReturn(false); DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_NonExisting_ExportFile_Should_Throw_DocxWriterException() throws DocxWriterException { exportFile = Mockito.mock(File.class); Mockito.when(exportFile.exists()).thenReturn(false); DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_Non_Writeable_ExportFile_Should_Throw_DocxWriterException() throws DocxWriterException { exportFile = Mockito.mock(File.class); Mockito.when(exportFile.exists()).thenReturn(true); Mockito.when(exportFile.canWrite()).thenReturn(false); DocxWriter writer = buildDocxWriter(); writer.export(); }
@Test(expected = DocxWriterException.class) public void export_With_Export_Compile_Failed_Should_Throw_DocxWriterException() throws DocxWriterException, DocxExporterException { Mockito.doThrow(DocxExporterException.class).when(exporter).compile(Matchers.any(File.class)); DocxWriter writer = buildDocxWriter(); writer.export(); }