diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2013-10-06 18:08:50 +0200 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2013-10-06 18:09:23 +0200 |
commit | 764ea21c9225e037a8d7cbb3a24626ee9c2a01ec (patch) | |
tree | 661f595e073f883270a954222bccf5f07221a3e4 /org.jacoco.report.test | |
parent | cdb42efaf762d8ad062302b08937fe1d60b93c98 (diff) | |
download | jacoco-764ea21c9225e037a8d7cbb3a24626ee9c2a01ec.tar.gz |
Do not render source files page if no source information is available.
Diffstat (limited to 'org.jacoco.report.test')
3 files changed, 126 insertions, 5 deletions
diff --git a/org.jacoco.report.test/src/org/jacoco/report/MemoryMultiReportOutput.java b/org.jacoco.report.test/src/org/jacoco/report/MemoryMultiReportOutput.java index ccebe878..31059c1a 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/MemoryMultiReportOutput.java +++ b/org.jacoco.report.test/src/org/jacoco/report/MemoryMultiReportOutput.java @@ -14,6 +14,7 @@ package org.jacoco.report; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; @@ -65,6 +66,10 @@ public class MemoryMultiReportOutput implements IMultiReportOutput { path, files.keySet()), files.get(path)); } + public void assertNoFile(String path) { + assertNull(String.format("Unexpected file %s.", path), files.get(path)); + } + public void assertSingleFile(String path) { assertEquals(Collections.singleton(path), files.keySet()); } diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackagePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackagePageTest.java new file mode 100644 index 00000000..dcaefdc8 --- /dev/null +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackagePageTest.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2009, 2013 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc R. Hoffmann - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.report.internal.html.page; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.Reader; +import java.util.Arrays; +import java.util.Collections; + +import org.jacoco.core.analysis.IClassCoverage; +import org.jacoco.core.analysis.IPackageCoverage; +import org.jacoco.core.analysis.ISourceFileCoverage; +import org.jacoco.core.internal.analysis.ClassCoverageImpl; +import org.jacoco.core.internal.analysis.PackageCoverageImpl; +import org.jacoco.core.internal.analysis.SourceFileCoverageImpl; +import org.jacoco.report.ISourceFileLocator; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link PackageSourcePage}. + */ +public class PackagePageTest extends PageTestBase { + + private IPackageCoverage node; + private ISourceFileLocator sourceLocator; + + private PackagePage page; + + @Before + @Override + public void setup() throws Exception { + super.setup(); + sourceLocator = new ISourceFileLocator() { + + public int getTabWidth() { + return 4; + } + + public Reader getSourceFile(String packageName, String fileName) + throws IOException { + return null; + } + }; + } + + @Test + public void testContentsWithSource() throws Exception { + IClassCoverage class1 = new ClassCoverageImpl( + "org/jacoco/example/Foo1", 0x1000, null, "java/lang/Object", + null); + IClassCoverage class2 = new ClassCoverageImpl( + "org/jacoco/example/Foo2", 0x2000, null, "java/lang/Object", + null); + ISourceFileCoverage src1 = new SourceFileCoverageImpl("Src1.java", + "org/jacoco/example"); + node = new PackageCoverageImpl("org/jacoco/example", Arrays.asList( + class1, class2), Arrays.asList(src1)); + + page = new PackagePage(node, null, sourceLocator, rootFolder, context); + page.render(); + + final Document doc = support.parse(output.getFile("index.html")); + + // Expect "Source Files" links + assertEquals("index.source.html", + support.findStr(doc, "/html/body/div[1]/span[1]/a/@href")); + assertEquals("el_source", + support.findStr(doc, "/html/body/div[1]/span[1]/a/@class")); + assertEquals("Source Files", + support.findStr(doc, "/html/body/div[1]/span[1]/a")); + assertEquals("el_class", support.findStr(doc, + "/html/body/table[1]/tbody/tr[1]/td[1]/a/@class")); + assertEquals("Foo1", + support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a")); + assertEquals("el_class", support.findStr(doc, + "/html/body/table[1]/tbody/tr[2]/td[1]/a/@class")); + assertEquals("Foo2", + support.findStr(doc, "/html/body/table[1]/tbody/tr[2]/td[1]/a")); + + output.assertFile("index.source.html"); + } + + @Test + public void testContentsNoSource() throws Exception { + IClassCoverage class1 = new ClassCoverageImpl( + "org/jacoco/example/Foo1", 0x1000, null, "java/lang/Object", + null); + IClassCoverage class2 = new ClassCoverageImpl( + "org/jacoco/example/Foo2", 0x2000, null, "java/lang/Object", + null); + node = new PackageCoverageImpl("org/jacoco/example", Arrays.asList( + class1, class2), Collections.<ISourceFileCoverage> emptyList()); + + page = new PackagePage(node, null, sourceLocator, rootFolder, context); + page.render(); + + // Expect no "Source Files" link + final Document doc = support.parse(output.getFile("index.html")); + assertEquals("Sessions", + support.findStr(doc, "/html/body/div[1]/span[1]/a")); + + // Expect no source files page: + output.assertNoFile("index.source.html"); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackageSourcePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackageSourcePageTest.java index 8a84db96..b1228f27 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackageSourcePageTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackageSourcePageTest.java @@ -80,7 +80,7 @@ public class PackageSourcePageTest extends PageTestBase { } public String getLink(ReportOutputFolder base) { - return "package.html"; + return "index.html"; } }; } @@ -91,11 +91,8 @@ public class PackageSourcePageTest extends PageTestBase { context, packagePageLink); page.render(); - System.out.println(new String(output.getFile("index.source.html"), - "UTF-8")); - final Document doc = support.parse(output.getFile("index.source.html")); - assertEquals("package.html", + assertEquals("index.html", support.findStr(doc, "/html/body/div[1]/span[1]/a/@href")); assertEquals("el_class", support.findStr(doc, "/html/body/div[1]/span[1]/a/@class")); |