aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2019-01-21 19:21:01 +0100
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2019-01-21 19:21:01 +0100
commitb7441f2b51b3d147554845710c809e5a562dc36f (patch)
treef7e9321459855f2dc0f3a3240ffd6f32df16410e
parentd0a0577f70b5bc4f42ce6af603b783835a014b82 (diff)
downloadjacoco-b7441f2b51b3d147554845710c809e5a562dc36f.tar.gz
Replace empty table in HTML report by messages (#833)
-rw-r--r--org.jacoco.doc/docroot/doc/changes.html3
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/BundlePageTest.java34
-rw-r--r--org.jacoco.report/src/org/jacoco/report/internal/html/page/BundlePage.java13
3 files changed, 50 insertions, 0 deletions
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index c8334399..e673eb5f 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -51,6 +51,9 @@
(GitHub <a href="https://github.com/jacoco/jacoco/issues/818">#818</a>).</li>
<li>HTML report shows message when analyzed class does not match executed
(GitHub <a href="https://github.com/jacoco/jacoco/issues/819">#819</a>).</li>
+ <li>HTML report shows message when no class files specified and when
+ none of the analyzed classes contain code relevant for code coverage
+ (GitHub <a href="https://github.com/jacoco/jacoco/issues/833">#833</a>).</li>
<li>Empty class and sourcefile nodes are preserved and available in XML report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/817">#817</a>).</li>
<li>Agent avoids conflicts with other agents when running on Java 9+
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/BundlePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/BundlePageTest.java
index 5b2f943e..716249cf 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/BundlePageTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/BundlePageTest.java
@@ -74,4 +74,38 @@ public class BundlePageTest extends PageTestBase {
support.findStr(doc, "count(/html/body/table[1]/tbody/tr)"));
}
+ @Test
+ public void should_render_message_when_no_class_files_specified()
+ throws Exception {
+ final IBundleCoverage node = new BundleCoverageImpl("bundle",
+ Collections.<IPackageCoverage> emptySet());
+
+ final BundlePage page = new BundlePage(node, null, null, rootFolder,
+ context);
+ page.render();
+
+ final Document doc = support.parse(output.getFile("index.html"));
+ assertEquals("No class files specified.",
+ support.findStr(doc, "/html/body/p"));
+ }
+
+ @Test
+ public void should_render_message_when_all_classes_empty()
+ throws Exception {
+ final ClassCoverageImpl emptyClass = new ClassCoverageImpl(
+ "example/Class", 0, false);
+ final IBundleCoverage node = new BundleCoverageImpl("bundle",
+ Collections.<IClassCoverage> singleton(emptyClass),
+ Collections.<ISourceFileCoverage> emptySet());
+
+ final BundlePage page = new BundlePage(node, null, null, rootFolder,
+ context);
+ page.render();
+
+ final Document doc = support.parse(output.getFile("index.html"));
+ assertEquals(
+ "None of the analyzed classes contain code relevant for code coverage.",
+ support.findStr(doc, "/html/body/p"));
+ }
+
}
diff --git a/org.jacoco.report/src/org/jacoco/report/internal/html/page/BundlePage.java b/org.jacoco.report/src/org/jacoco/report/internal/html/page/BundlePage.java
index 55840db0..403269c9 100644
--- a/org.jacoco.report/src/org/jacoco/report/internal/html/page/BundlePage.java
+++ b/org.jacoco.report/src/org/jacoco/report/internal/html/page/BundlePage.java
@@ -18,6 +18,7 @@ import org.jacoco.core.analysis.ICoverageNode;
import org.jacoco.core.analysis.IPackageCoverage;
import org.jacoco.report.ISourceFileLocator;
import org.jacoco.report.internal.ReportOutputFolder;
+import org.jacoco.report.internal.html.HTMLElement;
import org.jacoco.report.internal.html.IHTMLReportContext;
/**
@@ -85,4 +86,16 @@ public class BundlePage extends TablePage<ICoverageNode> {
return "index.html";
}
+ @Override
+ protected void content(HTMLElement body) throws IOException {
+ if (bundle.getPackages().isEmpty()) {
+ body.p().text("No class files specified.");
+ } else if (bundle.isEmpty()) {
+ body.p().text(
+ "None of the analyzed classes contain code relevant for code coverage.");
+ } else {
+ super.content(body);
+ }
+ }
+
}