Skip to content

Commit b7441f2

Browse files
Godinmarchof
authored andcommitted
Replace empty table in HTML report by messages (#833)
1 parent d0a0577 commit b7441f2

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ <h3>New Features</h3>
5151
(GitHub <a href="https://github.com/jacoco/jacoco/issues/818">#818</a>).</li>
5252
<li>HTML report shows message when analyzed class does not match executed
5353
(GitHub <a href="https://github.com/jacoco/jacoco/issues/819">#819</a>).</li>
54+
<li>HTML report shows message when no class files specified and when
55+
none of the analyzed classes contain code relevant for code coverage
56+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/833">#833</a>).</li>
5457
<li>Empty class and sourcefile nodes are preserved and available in XML report
5558
(GitHub <a href="https://github.com/jacoco/jacoco/issues/817">#817</a>).</li>
5659
<li>Agent avoids conflicts with other agents when running on Java 9+

org.jacoco.report.test/src/org/jacoco/report/internal/html/page/BundlePageTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,38 @@ Collections.<IClassCoverage> emptySet(),
7474
support.findStr(doc, "count(/html/body/table[1]/tbody/tr)"));
7575
}
7676

77+
@Test
78+
public void should_render_message_when_no_class_files_specified()
79+
throws Exception {
80+
final IBundleCoverage node = new BundleCoverageImpl("bundle",
81+
Collections.<IPackageCoverage> emptySet());
82+
83+
final BundlePage page = new BundlePage(node, null, null, rootFolder,
84+
context);
85+
page.render();
86+
87+
final Document doc = support.parse(output.getFile("index.html"));
88+
assertEquals("No class files specified.",
89+
support.findStr(doc, "/html/body/p"));
90+
}
91+
92+
@Test
93+
public void should_render_message_when_all_classes_empty()
94+
throws Exception {
95+
final ClassCoverageImpl emptyClass = new ClassCoverageImpl(
96+
"example/Class", 0, false);
97+
final IBundleCoverage node = new BundleCoverageImpl("bundle",
98+
Collections.<IClassCoverage> singleton(emptyClass),
99+
Collections.<ISourceFileCoverage> emptySet());
100+
101+
final BundlePage page = new BundlePage(node, null, null, rootFolder,
102+
context);
103+
page.render();
104+
105+
final Document doc = support.parse(output.getFile("index.html"));
106+
assertEquals(
107+
"None of the analyzed classes contain code relevant for code coverage.",
108+
support.findStr(doc, "/html/body/p"));
109+
}
110+
77111
}

org.jacoco.report/src/org/jacoco/report/internal/html/page/BundlePage.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jacoco.core.analysis.IPackageCoverage;
1919
import org.jacoco.report.ISourceFileLocator;
2020
import org.jacoco.report.internal.ReportOutputFolder;
21+
import org.jacoco.report.internal.html.HTMLElement;
2122
import org.jacoco.report.internal.html.IHTMLReportContext;
2223

2324
/**
@@ -85,4 +86,16 @@ protected String getFileName() {
8586
return "index.html";
8687
}
8788

89+
@Override
90+
protected void content(HTMLElement body) throws IOException {
91+
if (bundle.getPackages().isEmpty()) {
92+
body.p().text("No class files specified.");
93+
} else if (bundle.isEmpty()) {
94+
body.p().text(
95+
"None of the analyzed classes contain code relevant for code coverage.");
96+
} else {
97+
super.content(body);
98+
}
99+
}
100+
88101
}

0 commit comments

Comments
 (0)