Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a guard and a test for it

  • Loading branch information...
commit 48851761b4be180a5baead56cf662e1254d2c6fa 1 parent 542f473
@bassman5 authored
View
31 src/main/java/com/mickdudley/concordion/ConcordionReportMojo.java
@@ -21,7 +21,7 @@
public static final String PLUGIN_NAME = "Concordion-Report ";
public static final String DEFAULT_REPORT_DIR = "concordion";
- private boolean skip = false;
+ private boolean skipReportGeneration = false;
/**
* Output folder where the main page of the report will be generated. Note that this parameter is only relevant if
* the goal is run directly from the command line or from the default lifecycle. If the goal is run indirectly as
@@ -101,7 +101,7 @@ public boolean isExternalReport()
@Override
public boolean canGenerateReport()
{
- skip = true;
+ skipReportGeneration = true;
File sourceDir = new File(this.concordionDir);
if (! sourceDir.isDirectory()) {
@@ -114,7 +114,7 @@ public boolean canGenerateReport()
return false;
}
- skip = false;
+ skipReportGeneration = false;
return true;
}
@@ -124,19 +124,18 @@ public boolean canGenerateReport()
* @throws MavenReportException
*/
protected void executeReport(Locale locale) throws MavenReportException {
- if (skip) {
- return;
- }
-
- File directory = new File (getOutputDirectory());
- if ( !directory.exists() ) {
- directory.mkdirs();
- }
-
- try {
- FileUtils.copyDirectoryStructure(new File(concordionDir), directory);
- } catch (IOException e) {
- throw new MavenReportException("Error copying concordion reports", e);
+ if (!skipReportGeneration) {
+
+ File directory = new File (getOutputDirectory());
+ if ( !directory.exists() ) {
+ directory.mkdirs();
+ }
+
+ try {
+ FileUtils.copyDirectoryStructure(new File(concordionDir), directory);
+ } catch (IOException e) {
+ throw new MavenReportException("Error copying concordion reports", e);
+ }
}
}
View
8 src/test/java/com/mickdudley/concordion/ConcordionReportMojoTest.java
@@ -54,9 +54,9 @@ public void testBasic() throws MavenReportException {
}
@Test
- public void testNoConcordionReportDir () {
+ public void testNoConcordionReportDir () throws MavenReportException {
File outputDirectory = new File(getBasedir(), "target/test/unit/target/site");
- File concordionDir = new File(outputDirectory, "concordion");
+ File concordionDir = new File(outputDirectory, "concordion99");
MavenProject project = mock(MavenProject.class);
SiteRenderer siteRenderer = mock(SiteRenderer.class);
@@ -69,6 +69,10 @@ public void testNoConcordionReportDir () {
assertFalse(mojo.canGenerateReport());
+ // The report should never get run but checking that nothing bad would happen
+ mojo.executeReport(null);
+ assertFalse(concordionDir.exists());
+
}
@Test
Please sign in to comment.
Something went wrong with that request. Please try again.