[jscover] 41/69: Don't copy non-report files (https://github.com/tntim96/JSCover/issues/149)
Sylvestre Ledru
sylvestre at moszumanska.debian.org
Fri Aug 22 05:54:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
sylvestre pushed a commit to branch master
in repository jscover.
commit ebb103b6da02a903418aed8e8c29cd859b98febd
Author: tntim96 <tntim96 at gmail.com>
Date: Mon Jul 7 20:10:11 2014 +1000
Don't copy non-report files (https://github.com/tntim96/JSCover/issues/149)
---
History.md | 1 +
src/main/java/jscover/report/Main.java | 8 +++--
.../report/MainReportMergeAcceptanceTest.java | 27 +++++++++++++++--
src/test/java/jscover/report/MainTest.java | 35 ++++++++++++++--------
4 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/History.md b/History.md
index 016056b..f534fe5 100644
--- a/History.md
+++ b/History.md
@@ -1,5 +1,6 @@
1.0.13 / 2014-??-??
==================
+ * Don't copy non-report files (https://github.com/tntim96/JSCover/issues/149)
* Internal: Remove checked exception from public API
1.0.12 / 2014-07-02
diff --git a/src/main/java/jscover/report/Main.java b/src/main/java/jscover/report/Main.java
index af5e45c..d89f50d 100644
--- a/src/main/java/jscover/report/Main.java
+++ b/src/main/java/jscover/report/Main.java
@@ -347,6 +347,7 @@ import jscover.report.coberturaxml.CoberturaData;
import jscover.report.coberturaxml.CoberturaXmlGenerator;
import jscover.report.lcov.LCovGenerator;
import jscover.report.xml.XMLSummary;
+import jscover.util.IoService;
import jscover.util.IoUtils;
import java.io.File;
@@ -374,6 +375,7 @@ public class Main {
private LCovGenerator lCovGenerator = new LCovGenerator();
private JSONDataMerger jsonDataMerger = new JSONDataMerger();
private IoUtils ioUtils = IoUtils.getInstance();
+ private IoService ioService = new IoService(false);
private ConfigurationForReport config = new ConfigurationForReport();
public void setConfig(ConfigurationForReport config) {
@@ -408,15 +410,15 @@ public class Main {
}
private void mergeReports() {
- File firstReportDir = config.getMergeDirs().get(0);
- ioUtils.copyDir(firstReportDir, config.getMergeDestDir());
+ config.getMergeDestDir().mkdirs();
+ ioService.generateJSCoverFilesForWebServer(config.getMergeDestDir(), properties.getProperty("version"));
mergeJSON();
mergeOriginalSource();
}
private void mergeOriginalSource() {
File srcDir = new File(config.getMergeDestDir(), jscover.Main.reportSrcSubDir);
- for (int i = 1; i < config.getMergeDirs().size(); i++) {
+ for (int i = 0; i < config.getMergeDirs().size(); i++) {
File jsOriginalSrc = new File(config.getMergeDirs().get(i), jscover.Main.reportSrcSubDir);
if (jsOriginalSrc.exists())
ioUtils.copyDir(jsOriginalSrc, srcDir);
diff --git a/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java b/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java
index 1b1ffa9..878000d 100644
--- a/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java
+++ b/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java
@@ -344,14 +344,18 @@ package jscover.report;
import jscover.util.IoUtils;
import org.apache.commons.io.FileUtils;
+import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
+import java.util.Properties;
+import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
public class MainReportMergeAcceptanceTest {
private IoUtils ioUtils = IoUtils.getInstance();
@@ -377,11 +381,30 @@ public class MainReportMergeAcceptanceTest {
}
@Test
+ public void shouldGenerateReportFiles() throws IOException {
+ Properties properties = new Properties();
+ properties.load(jscover.Main.class.getResourceAsStream("/jscover/configuration.properties"));
+ Main.main(args);
+ File jsCoverHtml = new File(reportDir12, "jscoverage.html");
+ assertThat(jsCoverHtml.exists(), is(true));
+ File jsCoverJS = new File(reportDir12, "jscoverage.js");
+ assertThat(jsCoverJS.exists(), is(true));
+ assertThat(ioUtils.loadFromFileSystem(jsCoverHtml), Matchers.containsString(properties.getProperty("version")));
+ assertThat(ioUtils.loadFromFileSystem(jsCoverJS), endsWith("\njscoverage_isReport = true;"));
+ }
+
+ @Test
+ public void shouldNotCopyExtraFiles() throws IOException {
+ ioUtils.copy(data1, new File(reportDir1, "dummy.html"));
+ Main.main(args);
+ assertThat(new File(reportDir12, "dummy.html").exists(), is(false));
+ }
+
+ @Test
public void shouldMergeDataWithoutSource() throws IOException {
String expected = ioUtils.loadFromClassPath("/jscover/report/jscoverage-select-1-3.json");
Main.main(args);
String merged = ioUtils.loadFromFileSystem(new File(reportDir12, "jscoverage.json"));
assertThat(merged, equalTo(expected));
}
-
}
diff --git a/src/test/java/jscover/report/MainTest.java b/src/test/java/jscover/report/MainTest.java
index 8fe997a..6ac9df5 100644
--- a/src/test/java/jscover/report/MainTest.java
+++ b/src/test/java/jscover/report/MainTest.java
@@ -347,6 +347,7 @@ import jscover.report.coberturaxml.CoberturaData;
import jscover.report.coberturaxml.CoberturaXmlGenerator;
import jscover.report.lcov.LCovGenerator;
import jscover.report.xml.XMLSummary;
+import jscover.util.IoService;
import jscover.util.IoUtils;
import jscover.util.ReflectionUtils;
import org.apache.commons.io.FileUtils;
@@ -384,16 +385,19 @@ public class MainTest {
private @Mock LCovGenerator lCovGenerator;
private @Mock JSONDataMerger jsonDataMerger;
private @Mock IoUtils ioUtils;
+ private @Mock IoService ioService;
private @Mock ConfigurationForReport config;
@Before
public void setUp() {
+ Main.properties.setProperty("version", "theVersion");
ReflectionUtils.setField(main, "exitHelper", exitHelper);
ReflectionUtils.setField(main, "xmlSummary", xmlSummary);
ReflectionUtils.setField(main, "coberturaXmlGenerator", coberturaXmlGenerator);
ReflectionUtils.setField(main, "lCovGenerator", lCovGenerator);
ReflectionUtils.setField(main, "jsonDataMerger", jsonDataMerger);
ReflectionUtils.setField(main, "ioUtils", ioUtils);
+ ReflectionUtils.setField(main, "ioService", ioService);
ReflectionUtils.setField(main, "config", config);
}
@@ -542,11 +546,15 @@ public class MainTest {
File dir2 = new File("target/dir2");
mergeDirs.add(dir2);
File destDir = new File("target/dest-dir");
- File origSrc = new File(dir2, reportSrcSubDir);
- if (hasOriginalSrc)
- origSrc.mkdirs();
- else
- FileUtils.deleteDirectory(origSrc);
+ File origSrc1 = new File(dir1, reportSrcSubDir);
+ File origSrc2 = new File(dir2, reportSrcSubDir);
+ if (hasOriginalSrc) {
+ origSrc1.mkdirs();
+ origSrc2.mkdirs();
+ } else {
+ FileUtils.deleteDirectory(origSrc1);
+ FileUtils.deleteDirectory(origSrc2);
+ }
given(config.isMerge()).willReturn(true);
given(config.getMergeDestDir()).willReturn(destDir);
@@ -555,26 +563,27 @@ public class MainTest {
given(ioUtils.loadFromFileSystem(new File(dir2, "jscoverage.json"))).willReturn("json2");
SortedMap<String, FileData> mergedMap = new TreeMap<String, FileData>();
given(jsonDataMerger.mergeJSONCoverageStrings("json1","json2")).willReturn(mergedMap);
- given(jsonDataMerger.toJSON(mergedMap)).willReturn("mergedJSON");
+ given(jsonDataMerger.toJSON(argThat(sameInstance(mergedMap)))).willReturn("mergedJSON");
main.runMain(new String[]{});
- InOrder inOrder = inOrder(ioUtils);
+ InOrder inOrder = inOrder(ioService, ioUtils);
//Verify JSON merging
File mergedJson = new File(config.getMergeDestDir(), "jscoverage.json");
- verify(ioUtils).copy("mergedJSON", mergedJson);
-
- //Verify the merged JSON is copied after 1st directory is copied across
- inOrder.verify(ioUtils).copyDir(dir1, destDir);
+ //Verify report files generated
+ inOrder.verify(ioService).generateJSCoverFilesForWebServer(config.getMergeDestDir(), "theVersion");
+ //Verify JSON copied
inOrder.verify(ioUtils).copy("mergedJSON", mergedJson);
-
//Verify src copying
if (hasOriginalSrc) {
+ File src1 = new File(dir1, reportSrcSubDir);
File src2 = new File(dir2, reportSrcSubDir);
File srcDest = new File(destDir, reportSrcSubDir);
- verify(ioUtils).copyDir(src2, srcDest);
+ inOrder.verify(ioUtils).copyDir(src1, srcDest);
+ inOrder.verify(ioUtils).copyDir(src2, srcDest);
}
+
verifyZeroInteractions(exitHelper);
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jscover.git
More information about the pkg-java-commits
mailing list