aboutsummaryrefslogtreecommitdiffstats
path: root/org.jacoco.report.test/src/org/jacoco/report/internal
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2011-02-11 15:26:19 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2011-02-11 15:26:19 +0000
commit82c11be3dd19fc071f87fedc5782c11ca51a0732 (patch)
treedec4dd7ef6b8ad594bc3f6b78c12a35fc9e91812 /org.jacoco.report.test/src/org/jacoco/report/internal
parentfc417961148de5f05a7d86677a4265d4b91e9c63 (diff)
downloadplatform_external_jacoco-82c11be3dd19fc071f87fedc5782c11ca51a0732.tar.gz
platform_external_jacoco-82c11be3dd19fc071f87fedc5782c11ca51a0732.tar.bz2
platform_external_jacoco-82c11be3dd19fc071f87fedc5782c11ca51a0732.zip
Trac #53: Simplified reporting API, step 1.
Diffstat (limited to 'org.jacoco.report.test/src/org/jacoco/report/internal')
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/NormalizedFileNamesTest.java68
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/ReportOutputFolderTest.java106
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/LinkableStub.java4
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/PackagePageTest.java111
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java (renamed from org.jacoco.report.test/src/org/jacoco/report/internal/html/NodePageTest.java)39
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java (renamed from org.jacoco.report.test/src/org/jacoco/report/internal/html/ReportPageTest.java)31
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SessionsPageTest.java (renamed from org.jacoco.report.test/src/org/jacoco/report/internal/html/SessionsPageTest.java)18
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceFilePageTest.java (renamed from org.jacoco.report.test/src/org/jacoco/report/internal/html/SourceFilePageTest.java)59
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java (renamed from org.jacoco.report.test/src/org/jacoco/report/internal/html/SourceHighlighterTest.java)5
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/ResourcesTest.java2
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/table/BarColumnTest.java6
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/table/CounterColumnTest.java6
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/table/LabelColumnTest.java7
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/table/PercentageColumnTest.java6
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/table/TableTest.java5
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLGroupVisitorTest.java85
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLReportNodeHandlerTest.java182
17 files changed, 340 insertions, 400 deletions
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/NormalizedFileNamesTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/NormalizedFileNamesTest.java
new file mode 100644
index 00000000..53faacee
--- /dev/null
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/NormalizedFileNamesTest.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2011 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;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jacoco.report.internal.NormalizedFileNames;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link NormalizedFileNames}.
+ */
+public class NormalizedFileNamesTest {
+
+ private NormalizedFileNames nfn;
+
+ @Before
+ public void setup() {
+ nfn = new NormalizedFileNames();
+ }
+
+ @Test
+ public void testKeepLegalCharacters() {
+ String id = "Foo-bar_$15.class";
+ assertEquals(id, nfn.getFileName(id));
+ }
+
+ @Test
+ public void testReplaceIllegalCharacters() {
+ String id = "A/b C;";
+ assertEquals("A_b_C_", nfn.getFileName(id));
+ }
+
+ @Test
+ public void testReplaceIllegalCharactersNonUnique() {
+ assertEquals("F__", nfn.getFileName("F__"));
+ assertEquals("F__~1", nfn.getFileName("F**"));
+ assertEquals("F__~2", nfn.getFileName("F??"));
+
+ // Mapping must be reproducible
+ assertEquals("F__", nfn.getFileName("F__"));
+ assertEquals("F__~1", nfn.getFileName("F**"));
+ assertEquals("F__~2", nfn.getFileName("F??"));
+ }
+
+ @Test
+ public void testCaseAware() {
+ assertEquals("Hello", nfn.getFileName("Hello"));
+ assertEquals("HELLO~1", nfn.getFileName("HELLO"));
+ assertEquals("HeLLo~2", nfn.getFileName("HeLLo"));
+
+ // Mapping must be reproducible
+ assertEquals("Hello", nfn.getFileName("Hello"));
+ assertEquals("HELLO~1", nfn.getFileName("HELLO"));
+ assertEquals("HeLLo~2", nfn.getFileName("HeLLo"));
+ }
+
+}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/ReportOutputFolderTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/ReportOutputFolderTest.java
new file mode 100644
index 00000000..31298799
--- /dev/null
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/ReportOutputFolderTest.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2011 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.io.IOException;
+
+import org.jacoco.report.MemoryMultiReportOutput;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link ReportOutputFolder}.
+ */
+public class ReportOutputFolderTest {
+
+ private MemoryMultiReportOutput output;
+
+ private ReportOutputFolder root;
+
+ @Before
+ public void setup() {
+ output = new MemoryMultiReportOutput();
+ root = new ReportOutputFolder(output);
+ }
+
+ @After
+ public void teardown() throws IOException {
+ output.close();
+ output.assertAllClosed();
+ }
+
+ @Test
+ public void testFileInRoot() throws IOException {
+ root.createFile("test.html").close();
+ output.assertSingleFile("test.html");
+ }
+
+ @Test
+ public void testSubfolderInstance() throws IOException {
+ final ReportOutputFolder folder1 = root.subFolder("folder1");
+ final ReportOutputFolder folder2 = root.subFolder("folder1");
+ assertSame(folder1, folder2);
+ }
+
+ @Test
+ public void testFileInSubFolder() throws IOException {
+ root.subFolder("folderA").subFolder("folderB").createFile("test.html")
+ .close();
+ output.assertSingleFile("folderA/folderB/test.html");
+ output.close();
+ output.assertAllClosed();
+ }
+
+ @Test
+ public void testRelativeLinkInSameFolder() throws IOException {
+ final ReportOutputFolder base = root.subFolder("f1").subFolder("f2");
+ assertEquals("test.html", base.getLink(base, "test.html"));
+ }
+
+ @Test
+ public void testRelativeLinkInParentFolder() throws IOException {
+ final ReportOutputFolder base = root.subFolder("f1").subFolder("f2");
+ assertEquals("../../test.html", root.getLink(base, "test.html"));
+ }
+
+ @Test
+ public void testRelativeLinkInSubFolder() throws IOException {
+ final ReportOutputFolder folder = root.subFolder("f1").subFolder("f2");
+ assertEquals("f1/f2/test.html", folder.getLink(root, "test.html"));
+ }
+
+ @Test
+ public void testRelativeLinkInSibling1() throws IOException {
+ final ReportOutputFolder folder = root.subFolder("f1").subFolder("f2");
+ final ReportOutputFolder base = root.subFolder("g1").subFolder("g2");
+ assertEquals("../../f1/f2/test.html", folder.getLink(base, "test.html"));
+ }
+
+ @Test
+ public void testRelativeLinkInSibling2() throws IOException {
+ final ReportOutputFolder folder = root.subFolder("f1").subFolder("f2");
+ final ReportOutputFolder base = root.subFolder("f1").subFolder("g2");
+ assertEquals("../f2/test.html", folder.getLink(base, "test.html"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidRelativeLink() throws IOException {
+ final ReportOutputFolder folder = root.subFolder("f1").subFolder("f2");
+ final ReportOutputFolder base = new ReportOutputFolder(
+ new MemoryMultiReportOutput()).subFolder("g1");
+ folder.getLink(base, "test.html");
+ }
+}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/LinkableStub.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/LinkableStub.java
index 805cb072..d2625029 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/LinkableStub.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/LinkableStub.java
@@ -11,7 +11,7 @@
*******************************************************************************/
package org.jacoco.report.internal.html;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
/**
* Stub implementation for {@link ILinkable}.
@@ -22,7 +22,7 @@ public class LinkableStub implements ILinkable {
private final String label;
private final String style;
- LinkableStub(String link, String label, String style) {
+ public LinkableStub(String link, String label, String style) {
this.link = link;
this.label = label;
this.style = style;
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/PackagePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/PackagePageTest.java
deleted file mode 100644
index 86e63f1e..00000000
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/PackagePageTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2011 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;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Locale;
-
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.IClassCoverage;
-import org.jacoco.core.analysis.ICoverageNode.ElementType;
-import org.jacoco.core.analysis.IPackageCoverage;
-import org.jacoco.core.analysis.ISourceFileCoverage;
-import org.jacoco.core.internal.analysis.PackageCoverageImpl;
-import org.jacoco.report.ILanguageNames;
-import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
-import org.jacoco.report.internal.html.index.IIndexUpdate;
-import org.jacoco.report.internal.html.resources.Resources;
-import org.jacoco.report.internal.html.table.Table;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link PackagePage}.
- */
-public class PackagePageTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private IHTMLReportContext context;
-
- private PackagePage page;
-
- @Before
- public void setup() {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- context = new IHTMLReportContext() {
-
- public ILanguageNames getLanguageNames() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public Resources getResources() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public Table getTable() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public String getFooterText() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public ILinkable getSessionsPage() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public String getOutputEncoding() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public IIndexUpdate getIndexUpdate() {
- throw new AssertionError("Unexpected method call.");
- }
-
- public Locale getLocale() {
- throw new AssertionError("Unexpected method call.");
- }
- };
- Collection<IClassCoverage> classes = Collections.emptyList();
- Collection<ISourceFileCoverage> sources = Collections.emptyList();
- final IPackageCoverage node = new PackageCoverageImpl("foo", classes,
- sources);
- page = new PackagePage(node, null, root, context);
- }
-
- @Test(expected = AssertionError.class)
- public void testVisitChildNegative1() {
- page.visitChild(new CoverageNodeImpl(ElementType.GROUP, "Foo"));
- }
-
- @Test(expected = AssertionError.class)
- public void testVisitChildNegative2() {
- page.visitChild(new CoverageNodeImpl(ElementType.BUNDLE, "Foo"));
- }
-
- @Test(expected = AssertionError.class)
- public void testVisitChildNegative3() {
- page.visitChild(new CoverageNodeImpl(ElementType.PACKAGE, "Foo"));
- }
-
- @Test(expected = AssertionError.class)
- public void testVisitChildNegative4() {
- page.visitChild(new CoverageNodeImpl(ElementType.METHOD, "Foo"));
- }
-
-}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/NodePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java
index 31040533..5067b1ec 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/NodePageTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java
@@ -9,9 +9,10 @@
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
-package org.jacoco.report.internal.html;
+package org.jacoco.report.internal.html.page;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import java.io.IOException;
import java.util.Locale;
@@ -19,11 +20,13 @@ import java.util.Locale;
import org.jacoco.core.analysis.CoverageNodeImpl;
import org.jacoco.core.analysis.ICoverageNode;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
-import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.report.ILanguageNames;
-import org.jacoco.report.IReportVisitor;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
+import org.jacoco.report.internal.html.HTMLElement;
+import org.jacoco.report.internal.html.IHTMLReportContext;
+import org.jacoco.report.internal.html.ILinkable;
+import org.jacoco.report.internal.html.LinkableStub;
import org.jacoco.report.internal.html.index.IIndexUpdate;
import org.jacoco.report.internal.html.resources.Resources;
import org.jacoco.report.internal.html.resources.Styles;
@@ -45,9 +48,9 @@ public class NodePageTest {
private CoverageNodeImpl node;
- private NodePage page;
+ private NodePage<ICoverageNode> page;
- private class TestNodePage extends NodePage {
+ private class TestNodePage extends NodePage<ICoverageNode> {
protected TestNodePage(ICoverageNode node) {
super(node, null, root, NodePageTest.this.context);
@@ -62,10 +65,6 @@ public class NodePageTest {
return "index.html";
}
- public IReportVisitor visitChild(ICoverageNode node) {
- throw new UnsupportedOperationException();
- }
-
}
@Before
@@ -113,22 +112,14 @@ public class NodePageTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
@Test
public void testGetNode() throws IOException {
- node.increment(new CoverageNodeImpl(ElementType.GROUP, "Foo") {
- {
- branchCounter = CounterImpl.getInstance(15, 8);
- }
- });
- page.visitEnd(null);
- assertEquals(node.getName(), page.getNode().getName());
- assertEquals(node.getElementType(), page.getNode().getElementType());
- assertEquals(CounterImpl.getInstance(15, 8), page.getNode()
- .getBranchCounter());
+ assertSame(node, page.getNode());
}
@Test
@@ -141,10 +132,4 @@ public class NodePageTest {
assertEquals("el_group", page.getLinkStyle());
}
- @Test
- public void testVisitEnd() throws IOException {
- page.visitEnd(null);
- output.assertSingleFile("index.html");
- }
-
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/ReportPageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java
index 20f88ee4..6e18fef4 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/ReportPageTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java
@@ -9,7 +9,7 @@
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
-package org.jacoco.report.internal.html;
+package org.jacoco.report.internal.html.page;
import static org.junit.Assert.assertEquals;
@@ -18,7 +18,12 @@ import java.util.Locale;
import org.jacoco.report.ILanguageNames;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
+import org.jacoco.report.internal.html.HTMLElement;
+import org.jacoco.report.internal.html.HTMLSupport;
+import org.jacoco.report.internal.html.IHTMLReportContext;
+import org.jacoco.report.internal.html.ILinkable;
+import org.jacoco.report.internal.html.LinkableStub;
import org.jacoco.report.internal.html.index.IIndexUpdate;
import org.jacoco.report.internal.html.resources.Resources;
import org.jacoco.report.internal.html.resources.Styles;
@@ -53,17 +58,6 @@ public class ReportPageTest {
}
@Override
- protected void headExtra(HTMLElement head) throws IOException {
- super.headExtra(head);
- head.script("text/javascript", "test.js");
- }
-
- @Override
- protected String getOnload() {
- return "init()";
- }
-
- @Override
protected void content(HTMLElement body) throws IOException {
body.div("testcontent").text("Hello Test");
}
@@ -129,7 +123,8 @@ public class ReportPageTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
@@ -141,7 +136,7 @@ public class ReportPageTest {
@Test
public void testPageContent() throws Exception {
- page.renderDocument();
+ page.render();
final HTMLSupport support = new HTMLSupport();
final Document doc = support.parse(output.getFile("Test.html"));
@@ -149,12 +144,6 @@ public class ReportPageTest {
assertEquals(".resources/report.css", support.findStr(doc,
"/html/head/link[@rel='stylesheet']/@href"));
- // extra head
- assertEquals("test.js", support.findStr(doc, "/html/head/script/@src"));
-
- // onload handler
- assertEquals("init()", support.findStr(doc, "/html/body/@onload"));
-
// bread crumb
assertEquals("Report", support.findStr(doc,
"/html/body/div[@class='breadcrumb']/a[1]/text()"));
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/SessionsPageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SessionsPageTest.java
index 3fad3e4a..f9fe548c 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/SessionsPageTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SessionsPageTest.java
@@ -9,7 +9,7 @@
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
-package org.jacoco.report.internal.html;
+package org.jacoco.report.internal.html.page;
import static org.junit.Assert.assertEquals;
@@ -25,7 +25,12 @@ import org.jacoco.core.data.SessionInfo;
import org.jacoco.report.ILanguageNames;
import org.jacoco.report.JavaNames;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
+import org.jacoco.report.internal.html.HTMLElement;
+import org.jacoco.report.internal.html.HTMLSupport;
+import org.jacoco.report.internal.html.IHTMLReportContext;
+import org.jacoco.report.internal.html.ILinkable;
+import org.jacoco.report.internal.html.LinkableStub;
import org.jacoco.report.internal.html.index.ElementIndex;
import org.jacoco.report.internal.html.index.IIndexUpdate;
import org.jacoco.report.internal.html.resources.Resources;
@@ -99,7 +104,8 @@ public class SessionsPageTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
@@ -128,7 +134,7 @@ public class SessionsPageTest {
public void testEmptyContent() throws Exception {
final SessionsPage page = new SessionsPage(noSessions, noExecutionData,
index, null, root, context);
- page.renderDocument();
+ page.render();
final HTMLSupport support = new HTMLSupport();
final Document doc = support.parse(output.getFile(".sessions.html"));
assertEquals("No session information available.",
@@ -145,7 +151,7 @@ public class SessionsPageTest {
sessions.add(new SessionInfo("Session-C", 0, 0));
final SessionsPage page = new SessionsPage(sessions, noExecutionData,
index, null, root, context);
- page.renderDocument();
+ page.render();
final HTMLSupport support = new HTMLSupport();
final Document doc = support.parse(output.getFile(".sessions.html"));
assertEquals("el_session", support.findStr(doc,
@@ -186,7 +192,7 @@ public class SessionsPageTest {
final SessionsPage page = new SessionsPage(noSessions, data, index,
null, root, context);
- page.renderDocument();
+ page.render();
final HTMLSupport support = new HTMLSupport();
final Document doc = support.parse(output.getFile(".sessions.html"));
assertEquals("el_class", support.findStr(doc,
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/SourceFilePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceFilePageTest.java
index 45752118..0d83f779 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/SourceFilePageTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceFilePageTest.java
@@ -9,24 +9,24 @@
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
-package org.jacoco.report.internal.html;
+package org.jacoco.report.internal.html.page;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Locale;
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.core.internal.analysis.SourceFileCoverageImpl;
-import org.jacoco.report.DirectorySourceFileLocator;
import org.jacoco.report.ILanguageNames;
-import org.jacoco.report.ISourceFileLocator;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
+import org.jacoco.report.internal.html.HTMLSupport;
+import org.jacoco.report.internal.html.IHTMLReportContext;
+import org.jacoco.report.internal.html.ILinkable;
+import org.jacoco.report.internal.html.LinkableStub;
import org.jacoco.report.internal.html.index.IIndexUpdate;
import org.jacoco.report.internal.html.resources.Resources;
import org.jacoco.report.internal.html.resources.Styles;
@@ -47,10 +47,10 @@ public class SourceFilePageTest {
private IHTMLReportContext context;
- private ISourceFileLocator locator;
+ private Reader sourceReader;
@Before
- public void setup() {
+ public void setup() throws IOException {
output = new MemoryMultiReportOutput();
root = new ReportOutputFolder(output);
final Resources resources = new Resources(root);
@@ -89,32 +89,25 @@ public class SourceFilePageTest {
return Locale.ENGLISH;
}
};
- locator = new DirectorySourceFileLocator(new File("./src"), "UTF-8");
+ sourceReader = new InputStreamReader(
+ new FileInputStream(
+ "./src/org/jacoco/report/internal/html/page/SourceFilePageTest.java"),
+ "UTF-8");
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
- @Test(expected = AssertionError.class)
- public void testVisitChildNegative() {
- final SourceFileCoverageImpl node = new SourceFileCoverageImpl(
- "SourceFilePageTest.java", "org/jacoco/report/html");
- final SourceFilePage page = new SourceFilePage(node, null, root,
- context);
- page.visitChild(new CoverageNodeImpl(ElementType.CLASS, "Foo"));
- }
-
@Test
public void testContents() throws Exception {
final SourceFileCoverageImpl node = new SourceFileCoverageImpl(
"SourceFilePageTest.java", "org/jacoco/report/internal/html");
- final SourceFilePage page = new SourceFilePage(node, null, root,
- context);
- page.visitEnd(locator);
-
- assertTrue(page.exists());
+ final SourceFilePage page = new SourceFilePage(node, sourceReader,
+ null, root, context);
+ page.render();
final HTMLSupport support = new HTMLSupport();
final Document result = support.parse(output
@@ -139,16 +132,4 @@ public class SourceFilePageTest {
support.findStr(result, "/html/body/pre/span[1]/@id"));
}
- @Test
- public void testNoSource() throws IOException {
- final SourceFileCoverageImpl node = new SourceFileCoverageImpl(
- "DoesNotExist.java", "org/jacoco/report/html");
- final SourceFilePage page = new SourceFilePage(node, null, root,
- context);
- page.visitEnd(locator);
-
- assertFalse(page.exists());
- output.assertEmpty();
- }
-
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/SourceHighlighterTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java
index 9f65a3e6..15db391f 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/SourceHighlighterTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java
@@ -9,7 +9,7 @@
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
-package org.jacoco.report.internal.html;
+package org.jacoco.report.internal.html.page;
import static org.junit.Assert.assertEquals;
@@ -20,6 +20,9 @@ import java.util.Locale;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.core.internal.analysis.SourceNodeImpl;
+import org.jacoco.report.internal.html.HTMLDocument;
+import org.jacoco.report.internal.html.HTMLElement;
+import org.jacoco.report.internal.html.HTMLSupport;
import org.jacoco.report.internal.html.resources.Styles;
import org.junit.Before;
import org.junit.Test;
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/ResourcesTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/ResourcesTest.java
index 56d52022..fa7e4498 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/ResourcesTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/ResourcesTest.java
@@ -17,7 +17,7 @@ import java.io.IOException;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
import org.junit.Before;
import org.junit.Test;
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/BarColumnTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/BarColumnTest.java
index 8c1fc26e..444dda76 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/BarColumnTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/BarColumnTest.java
@@ -14,6 +14,7 @@ package org.jacoco.report.internal.html.table;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
@@ -24,7 +25,7 @@ import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
import org.jacoco.report.internal.html.HTMLDocument;
import org.jacoco.report.internal.html.HTMLElement;
import org.jacoco.report.internal.html.HTMLSupport;
@@ -66,7 +67,8 @@ public class BarColumnTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/CounterColumnTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/CounterColumnTest.java
index 8430fbcf..5bbdbd2c 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/CounterColumnTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/CounterColumnTest.java
@@ -15,6 +15,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
@@ -26,7 +27,7 @@ import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
import org.jacoco.report.internal.html.HTMLDocument;
import org.jacoco.report.internal.html.HTMLElement;
import org.jacoco.report.internal.html.HTMLSupport;
@@ -68,7 +69,8 @@ public class CounterColumnTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/LabelColumnTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/LabelColumnTest.java
index 8c8fe7fa..ed2d7cfc 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/LabelColumnTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/LabelColumnTest.java
@@ -14,11 +14,13 @@ package org.jacoco.report.internal.html.table;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+
import org.jacoco.core.analysis.CoverageNodeImpl;
import org.jacoco.core.analysis.ICoverageNode;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
import org.jacoco.report.internal.html.HTMLDocument;
import org.jacoco.report.internal.html.HTMLElement;
import org.jacoco.report.internal.html.HTMLSupport;
@@ -60,7 +62,8 @@ public class LabelColumnTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/PercentageColumnTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/PercentageColumnTest.java
index 263a3998..bbe963d8 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/PercentageColumnTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/PercentageColumnTest.java
@@ -14,6 +14,7 @@ package org.jacoco.report.internal.html.table;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.Comparator;
import java.util.Locale;
@@ -23,7 +24,7 @@ import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
import org.jacoco.report.internal.html.HTMLDocument;
import org.jacoco.report.internal.html.HTMLElement;
import org.jacoco.report.internal.html.HTMLSupport;
@@ -65,7 +66,8 @@ public class PercentageColumnTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/TableTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/TableTest.java
index b72956cc..50d2b594 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/TableTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/table/TableTest.java
@@ -26,7 +26,7 @@ import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
import org.jacoco.core.analysis.ICoverageNode.ElementType;
import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.ReportOutputFolder;
+import org.jacoco.report.internal.ReportOutputFolder;
import org.jacoco.report.internal.html.HTMLDocument;
import org.jacoco.report.internal.html.HTMLElement;
import org.jacoco.report.internal.html.HTMLSupport;
@@ -65,7 +65,8 @@ public class TableTest {
}
@After
- public void teardown() {
+ public void teardown() throws IOException {
+ output.close();
output.assertAllClosed();
}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLGroupVisitorTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLGroupVisitorTest.java
new file mode 100644
index 00000000..81e29fff
--- /dev/null
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLGroupVisitorTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2011 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.xml;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jacoco.report.ReportStructureTestDriver;
+import org.jacoco.report.xml.XMLFormatter;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * Unit tests for {@link XMLGroupVisitor}.
+ */
+public class XMLGroupVisitorTest {
+
+ private XMLElement root;
+
+ private StringWriter buffer;
+
+ private XMLSupport support;
+
+ private XMLGroupVisitor handler;
+
+ private ReportStructureTestDriver driver;
+
+ @Before
+ public void setup() throws Exception {
+ buffer = new StringWriter();
+ support = new XMLSupport(XMLFormatter.class);
+ root = new XMLDocument("report", "-//JACOCO//DTD Report 1.0//EN",
+ "report.dtd", "UTF-8", true, buffer);
+ root.attr("name", "Report");
+ handler = new XMLGroupVisitor(root, null);
+ driver = new ReportStructureTestDriver();
+ }
+
+ @Test
+ public void testVisitBundle() throws Exception {
+ driver.sendBundle(handler);
+ root.close();
+ final Document doc = getDocument();
+ assertEquals("bundle", support.findStr(doc, "//report/group/@name"));
+ }
+
+ @Test
+ public void testVisitGroup() throws Exception {
+ driver.sendGroup(handler);
+ root.close();
+ final Document doc = getDocument();
+ assertEquals("group", support.findStr(doc, "//report/group/@name"));
+ }
+
+ @Test
+ public void testVisitEnd() throws Exception {
+ driver.sendBundle(handler);
+ handler.visitEnd();
+ root.close();
+ final Document doc = getDocument();
+ assertEquals("33", support.findStr(doc,
+ "//report/counter[@type='BRANCH']/@covered"));
+ }
+
+ private Document getDocument() throws SAXException, IOException,
+ ParserConfigurationException {
+ return support.parse(buffer.toString());
+ }
+
+}
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLReportNodeHandlerTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLReportNodeHandlerTest.java
deleted file mode 100644
index b873252e..00000000
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLReportNodeHandlerTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2011 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.xml;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.ICoverageNode.ElementType;
-import org.jacoco.core.internal.analysis.CounterImpl;
-import org.jacoco.core.internal.analysis.MethodCoverageImpl;
-import org.jacoco.core.internal.analysis.SourceNodeImpl;
-import org.jacoco.report.IReportVisitor;
-import org.jacoco.report.xml.XMLFormatter;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-/**
- * Unit tests for {@link XMLReportNodeHandler}.
- */
-public class XMLReportNodeHandlerTest {
-
- private XMLElement root;
-
- private StringWriter buffer;
-
- private XMLSupport support;
-
- private XMLReportNodeHandler handler;
-
- @Before
- public void setup() throws Exception {
- buffer = new StringWriter();
- support = new XMLSupport(XMLFormatter.class);
- root = new XMLDocument("report", "-//JACOCO//DTD Report 1.0//EN",
- "report.dtd", "UTF-8", true, buffer);
- handler = new XMLReportNodeHandler(root, new CoverageNodeImpl(
- ElementType.GROUP, "Sample"));
- }
-
- @Test
- public void testRoot() throws Exception {
- final Document doc = getDocument();
- assertEquals("Sample", support.findStr(doc, "//report/@name"));
- }
-
- @Test
- public void testGroup() throws Exception {
- handler.visitChild(new CoverageNodeImpl(ElementType.GROUP, "Group1"))
- .visitEnd(null);
- final Document doc = getDocument();
- assertEquals("Group1", support.findStr(doc, "//report/group/@name"));
- }
-
- @Test
- public void testCounters() throws Exception {
- final CoverageNodeImpl node = new CoverageNodeImpl(ElementType.GROUP,
- "Group1") {
- {
- classCounter = CounterImpl.getInstance(9, 1);
- methodCounter = CounterImpl.getInstance(18, 2);
- branchCounter = CounterImpl.getInstance(27, 3);
- instructionCounter = CounterImpl.getInstance(36, 4);
- lineCounter = CounterImpl.getInstance(45, 5);
- }
- };
- handler.visitChild(node).visitEnd(null);
- final Document doc = getDocument();
- assertEquals("1", support.findStr(doc,
- "//report/group/counter[@type='CLASS']/@covered"));
- assertEquals("9", support.findStr(doc,
- "//report/group/counter[@type='CLASS']/@missed"));
- assertEquals("2", support.findStr(doc,
- "//report/group/counter[@type='METHOD']/@covered"));
- assertEquals("18", support.findStr(doc,
- "//report/group/counter[@type='METHOD']/@missed"));
- assertEquals("3", support.findStr(doc,
- "//report/group/counter[@type='BRANCH']/@covered"));
- assertEquals("27", support.findStr(doc,
- "//report/group/counter[@type='BRANCH']/@missed"));
- assertEquals("4", support.findStr(doc,
- "//report/group/counter[@type='INSTRUCTION']/@covered"));
- assertEquals("36", support.findStr(doc,
- "//report/group/counter[@type='INSTRUCTION']/@missed"));
- assertEquals("5", support.findStr(doc,
- "//report/group/counter[@type='LINE']/@covered"));
- assertEquals("45", support.findStr(doc,
- "//report/group/counter[@type='LINE']/@missed"));
- }
-
- @Test
- public void testPackage() throws Exception {
- handler.visitChild(
- new CoverageNodeImpl(ElementType.PACKAGE, "org.jacoco.example"))
- .visitEnd(null);
- final Document doc = getDocument();
- assertEquals("org.jacoco.example",
- support.findStr(doc, "//report/package/@name"));
- }
-
- @Test
- public void testClass() throws Exception {
- final IReportVisitor packageHandler = handler
- .visitChild(new CoverageNodeImpl(ElementType.PACKAGE,
- "org.jacoco.example"));
- packageHandler.visitChild(new SourceNodeImpl(ElementType.CLASS, "Foo"))
- .visitEnd(null);
- packageHandler.visitEnd(null);
- final Document doc = getDocument();
- assertEquals("Foo",
- support.findStr(doc, "//report/package/class/@name"));
- }
-
- @Test
- public void testMethod() throws Exception {
- final IReportVisitor packageHandler = handler
- .visitChild(new CoverageNodeImpl(ElementType.PACKAGE,
- "org.jacoco.example"));
- final IReportVisitor classHandler = packageHandler
- .visitChild(new SourceNodeImpl(ElementType.CLASS, "Foo"));
- MethodCoverageImpl node = new MethodCoverageImpl("doit", "()V", null);
- node.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 15);
- classHandler.visitChild(node).visitEnd(null);
- classHandler.visitEnd(null);
- packageHandler.visitEnd(null);
- final Document doc = getDocument();
- assertEquals("doit",
- support.findStr(doc, "//report/package/class/method/@name"));
- assertEquals("()V",
- support.findStr(doc, "//report/package/class/method/@desc"));
- assertEquals("15",
- support.findStr(doc, "//report/package/class/method/@line"));
- }
-
- @Test
- public void testSourcefile() throws Exception {
- final IReportVisitor packageHandler = handler
- .visitChild(new CoverageNodeImpl(ElementType.PACKAGE,
- "org.jacoco.example"));
- final SourceNodeImpl node = new SourceNodeImpl(ElementType.SOURCEFILE,
- "Foo.java");
- node.increment(CounterImpl.getInstance(1, 2),
- CounterImpl.getInstance(3, 4), 12);
- packageHandler.visitChild(node).visitEnd(null);
- packageHandler.visitEnd(null);
- final Document doc = getDocument();
- assertEquals("Foo.java",
- support.findStr(doc, "//report/package/sourcefile/@name"));
- assertEquals("12",
- support.findStr(doc, "//report/package/sourcefile/line/@nr"));
- assertEquals("1",
- support.findStr(doc, "//report/package/sourcefile/line/@mi"));
- assertEquals("2",
- support.findStr(doc, "//report/package/sourcefile/line/@ci"));
- assertEquals("3",
- support.findStr(doc, "//report/package/sourcefile/line/@mb"));
- assertEquals("4",
- support.findStr(doc, "//report/package/sourcefile/line/@cb"));
- }
-
- private Document getDocument() throws SAXException, IOException,
- ParserConfigurationException {
- handler.visitEnd(null);
- return support.parse(buffer.toString());
- }
-
-}