aboutsummaryrefslogtreecommitdiffstats
path: root/org.jacoco.report.test/src/org/jacoco/report/internal
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2013-09-24 01:50:50 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2013-09-24 01:50:50 +0200
commitcdb42efaf762d8ad062302b08937fe1d60b93c98 (patch)
tree4e8e0115146f6f980cf2a984762e14b120d6162e /org.jacoco.report.test/src/org/jacoco/report/internal
parent80e4ab959ee3e39cf56f757ce53c3deb1dbc5cd5 (diff)
downloadplatform_external_jacoco-cdb42efaf762d8ad062302b08937fe1d60b93c98.tar.gz
platform_external_jacoco-cdb42efaf762d8ad062302b08937fe1d60b93c98.tar.bz2
platform_external_jacoco-cdb42efaf762d8ad062302b08937fe1d60b93c98.zip
Add additional package page to HTML report listing source files instead
of classes.
Diffstat (limited to 'org.jacoco.report.test/src/org/jacoco/report/internal')
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackageSourcePageTest.java124
1 files changed, 124 insertions, 0 deletions
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
new file mode 100644
index 00000000..8a84db96
--- /dev/null
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PackageSourcePageTest.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * 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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.jacoco.core.analysis.IClassCoverage;
+import org.jacoco.core.analysis.ISourceFileCoverage;
+import org.jacoco.core.internal.analysis.PackageCoverageImpl;
+import org.jacoco.core.internal.analysis.SourceFileCoverageImpl;
+import org.jacoco.report.ISourceFileLocator;
+import org.jacoco.report.internal.ReportOutputFolder;
+import org.jacoco.report.internal.html.ILinkable;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+/**
+ * Unit tests for {@link PackageSourcePage}.
+ */
+public class PackageSourcePageTest extends PageTestBase {
+
+ private PackageCoverageImpl node;
+ private ISourceFileLocator sourceLocator;
+ private ILinkable packagePageLink;
+
+ private PackageSourcePage page;
+
+ @Before
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ ISourceFileCoverage src1 = new SourceFileCoverageImpl("Src1.java",
+ "org/jacoco/example");
+ ISourceFileCoverage src2 = new SourceFileCoverageImpl("Src2.java",
+ "org/jacoco/example");
+ node = new PackageCoverageImpl("org/jacoco/example",
+ Collections.<IClassCoverage> emptyList(), Arrays.asList(src1,
+ src2));
+ sourceLocator = new ISourceFileLocator() {
+
+ public int getTabWidth() {
+ return 4;
+ }
+
+ public Reader getSourceFile(String packageName, String fileName)
+ throws IOException {
+ return fileName.equals("Src1.java") ? new StringReader("")
+ : null;
+ }
+ };
+ packagePageLink = new ILinkable() {
+
+ public String getLinkStyle() {
+ fail();
+ return null;
+ }
+
+ public String getLinkLabel() {
+ fail();
+ return null;
+ }
+
+ public String getLink(ReportOutputFolder base) {
+ return "package.html";
+ }
+ };
+ }
+
+ @Test
+ public void testContents() throws Exception {
+ page = new PackageSourcePage(node, null, sourceLocator, rootFolder,
+ 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",
+ 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"));
+ assertEquals("Classes",
+ support.findStr(doc, "/html/body/div[1]/span[1]/a"));
+ assertEquals("el_source", support.findStr(doc,
+ "/html/body/table[1]/tbody/tr[1]/td[1]/a/@class"));
+ assertEquals("Src1.java",
+ support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a"));
+ assertEquals("el_source", support.findStr(doc,
+ "/html/body/table[1]/tbody/tr[2]/td[1]/span/@class"));
+ assertEquals("Src2.java", support.findStr(doc,
+ "/html/body/table[1]/tbody/tr[2]/td[1]/span"));
+ }
+
+ @Test
+ public void testGetSourceFilePages() throws Exception {
+ page = new PackageSourcePage(node, null, sourceLocator, rootFolder,
+ context, packagePageLink);
+ page.render();
+
+ assertNotNull(page.getSourceFilePage("Src1.java"));
+ assertNull(page.getSourceFilePage("Src2.java"));
+ }
+
+}