@Test public void testGetWriter() throws Exception { final String testData = "whoa whoa whoa, lois, this is not my batman cup"; final String filename = "testGetWriter.output"; final File outputDirectory = File.createTempFile("testGetWriter", null).getParentFile(); final File expectedFile = new File(outputDirectory, "/cdoc-report/" + filename); CDocReportMojo mojo = new CDocReportMojo(); Field fieldOutputDirectory = mojo.getClass().getDeclaredField("outputDirectory"); Field fieldOutputEncoding = mojo.getClass().getDeclaredField("outputEncoding"); fieldOutputDirectory.setAccessible(true); fieldOutputEncoding.setAccessible(true); fieldOutputDirectory.set(mojo, outputDirectory); fieldOutputEncoding.set(mojo, "utf-8"); final Documentation doc = mock(Documentation.class); when(doc.getDestinationFilename()).thenReturn(filename); try (Writer writer = mojo.getWriter(doc)) { IOUtils.write(testData.getBytes("utf-8"), writer, "utf-8"); } assertThat(expectedFile).exists(); try { assertThat(FileUtils.fileRead(expectedFile, "utf-8")).isEqualTo(testData); } finally { FileUtils.forceDelete(expectedFile); } }
Writer getWriter(final Documentation doc) throws MavenReportException { try { final File destinationFile = new File(getDestinationDirectory(), doc.getDestinationFilename()); if (!destinationFile.getParentFile().exists()) { FileUtils.forceMkdir(destinationFile.getParentFile()); } return new OutputStreamWriter(new FileOutputStream(destinationFile), Charset.forName(getOutputEncoding())); } catch (final IOException e) { throw new MavenReportException( "Failed to prepare output file for file " + doc.getSourceFile().getAbsolutePath(), e); } }
CDocReportMojo extends AbstractMavenReport { Writer getWriter(final Documentation doc) throws MavenReportException { try { final File destinationFile = new File(getDestinationDirectory(), doc.getDestinationFilename()); if (!destinationFile.getParentFile().exists()) { FileUtils.forceMkdir(destinationFile.getParentFile()); } return new OutputStreamWriter(new FileOutputStream(destinationFile), Charset.forName(getOutputEncoding())); } catch (final IOException e) { throw new MavenReportException( "Failed to prepare output file for file " + doc.getSourceFile().getAbsolutePath(), e); } } }
CDocReportMojo extends AbstractMavenReport { Writer getWriter(final Documentation doc) throws MavenReportException { try { final File destinationFile = new File(getDestinationDirectory(), doc.getDestinationFilename()); if (!destinationFile.getParentFile().exists()) { FileUtils.forceMkdir(destinationFile.getParentFile()); } return new OutputStreamWriter(new FileOutputStream(destinationFile), Charset.forName(getOutputEncoding())); } catch (final IOException e) { throw new MavenReportException( "Failed to prepare output file for file " + doc.getSourceFile().getAbsolutePath(), e); } } CDocReportMojo();  CDocReportMojo(final TextParser textParser, final ScriptExecutionDetailsParser detailsParser); }
CDocReportMojo extends AbstractMavenReport { Writer getWriter(final Documentation doc) throws MavenReportException { try { final File destinationFile = new File(getDestinationDirectory(), doc.getDestinationFilename()); if (!destinationFile.getParentFile().exists()) { FileUtils.forceMkdir(destinationFile.getParentFile()); } return new OutputStreamWriter(new FileOutputStream(destinationFile), Charset.forName(getOutputEncoding())); } catch (final IOException e) { throw new MavenReportException( "Failed to prepare output file for file " + doc.getSourceFile().getAbsolutePath(), e); } } CDocReportMojo();  CDocReportMojo(final TextParser textParser, final ScriptExecutionDetailsParser detailsParser); @Override boolean canGenerateReport(); @Override String getDescription(final Locale locale); @Override String getName(final Locale locale); @Override String getOutputName(); @Override boolean isExternalReport(); }
CDocReportMojo extends AbstractMavenReport { Writer getWriter(final Documentation doc) throws MavenReportException { try { final File destinationFile = new File(getDestinationDirectory(), doc.getDestinationFilename()); if (!destinationFile.getParentFile().exists()) { FileUtils.forceMkdir(destinationFile.getParentFile()); } return new OutputStreamWriter(new FileOutputStream(destinationFile), Charset.forName(getOutputEncoding())); } catch (final IOException e) { throw new MavenReportException( "Failed to prepare output file for file " + doc.getSourceFile().getAbsolutePath(), e); } } CDocReportMojo();  CDocReportMojo(final TextParser textParser, final ScriptExecutionDetailsParser detailsParser); @Override boolean canGenerateReport(); @Override String getDescription(final Locale locale); @Override String getName(final Locale locale); @Override String getOutputName(); @Override boolean isExternalReport();  }