diff options
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); + } + } + } |