diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-08-30 22:13:04 +0600 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-08-30 22:13:04 +0600 |
commit | e69ba4dbb015949c5d84ba7bbb0b53efac28bb23 (patch) | |
tree | 44cbe6d78216fcb3c37c0aca1dc7ed3fc09906fa /org.jacoco.report.test | |
parent | a888d873ac20357a4a11029bc84c5c4b48e394a3 (diff) | |
download | jacoco-e69ba4dbb015949c5d84ba7bbb0b53efac28bb23.tar.gz |
Fix EOLs
Diffstat (limited to 'org.jacoco.report.test')
30 files changed, 3491 insertions, 3491 deletions
diff --git a/org.jacoco.report.test/src/org/jacoco/report/FileMultiReportOutputTest.java b/org.jacoco.report.test/src/org/jacoco/report/FileMultiReportOutputTest.java index e94009ba..de265200 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/FileMultiReportOutputTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/FileMultiReportOutputTest.java @@ -1,61 +1,61 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-/**
- * Unit tests for {@link FileMultiReportOutput}.
- */
-public class FileMultiReportOutputTest {
-
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testCreateFileWithDirectories() throws IOException {
- final IMultiReportOutput output = new FileMultiReportOutput(
- folder.getRoot());
- final OutputStream stream = output.createFile("a/b/c/test");
- stream.write(1);
- stream.write(2);
- stream.write(3);
- stream.close();
- output.close();
-
- final InputStream actual = new FileInputStream(new File(
- folder.getRoot(), "a/b/c/test"));
- assertEquals(1, actual.read());
- assertEquals(2, actual.read());
- assertEquals(3, actual.read());
- assertEquals(-1, actual.read());
- }
-
- @Test(expected = IOException.class)
- public void testCreateFileNegative() throws IOException {
- folder.newFile("a");
- final IMultiReportOutput output = new FileMultiReportOutput(
- folder.getRoot());
- output.createFile("a/b/c/test");
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Unit tests for {@link FileMultiReportOutput}. + */ +public class FileMultiReportOutputTest { + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void testCreateFileWithDirectories() throws IOException { + final IMultiReportOutput output = new FileMultiReportOutput( + folder.getRoot()); + final OutputStream stream = output.createFile("a/b/c/test"); + stream.write(1); + stream.write(2); + stream.write(3); + stream.close(); + output.close(); + + final InputStream actual = new FileInputStream(new File( + folder.getRoot(), "a/b/c/test")); + assertEquals(1, actual.read()); + assertEquals(2, actual.read()); + assertEquals(3, actual.read()); + assertEquals(-1, actual.read()); + } + + @Test(expected = IOException.class) + public void testCreateFileNegative() throws IOException { + folder.newFile("a"); + final IMultiReportOutput output = new FileMultiReportOutput( + folder.getRoot()); + output.createFile("a/b/c/test"); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/JavaNamesTest.java b/org.jacoco.report.test/src/org/jacoco/report/JavaNamesTest.java index c0c001ff..78c265ef 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/JavaNamesTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/JavaNamesTest.java @@ -1,156 +1,156 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link JavaNames}.
- */
-public class JavaNamesTest {
-
- private ILanguageNames names;
-
- @Before
- public void setup() {
- names = new JavaNames();
- }
-
- @Test
- public void testGetPackageName1() {
- assertEquals("default", names.getPackageName(""));
- }
-
- @Test
- public void testGetPackageName2() {
- assertEquals("java.lang", names.getPackageName("java/lang"));
- }
-
- @Test
- public void testGetClassName1() {
- assertEquals("Main", names.getClassName("Main", null, null, null));
- }
-
- @Test
- public void testGetClassName2() {
- assertEquals("Object",
- names.getClassName("java/lang/Object", null, null, null));
- }
-
- @Test
- public void testGetClassName3() {
- assertEquals("Map.Entry",
- names.getClassName("java/util/Map$Entry", null, null, null));
- }
-
- @Test
- public void testGetClassName4() {
- assertEquals("Bar.new Object() {...}", names.getClassName(
- "com/foo/Bar$1", null, "java/lang/Object", new String[0]));
- }
-
- @Test
- public void testGetClassName5() {
- assertEquals("Bar.new ISample() {...}", names.getClassName(
- "com/foo/Bar$1", null, "java/lang/Object",
- new String[] { "org/foo/ISample" }));
- }
-
- @Test
- public void testGetClassName6() {
- assertEquals("Bar.1",
- names.getClassName("com/foo/Bar$1", null, null, null));
- }
-
- @Test
- public void testGetClassName7() {
- assertEquals("Strange.",
- names.getClassName("com/foo/Strange$", null, null, null));
- }
-
- @Test
- public void testGetQualifiedClassName1() {
- assertEquals("Foo", names.getQualifiedClassName("Foo"));
- }
-
- @Test
- public void testGetQualifiedClassName2() {
- assertEquals("java.lang.Object",
- names.getQualifiedClassName("java/lang/Object"));
- }
-
- @Test
- public void testGetQualifiedClassName3() {
- assertEquals("java.util.Map.Entry",
- names.getQualifiedClassName("java/util/Map$Entry"));
- }
-
- @Test
- public void testGetMethodName1() {
- assertEquals("wait()",
- names.getMethodName("java/lang/Object", "wait", "()V", null));
- }
-
- @Test
- public void testGetMethodName2() {
- assertEquals("remove(Object)",
- names.getMethodName("java/util/Collection", "remove",
- "(Ljava/lang/Object;)V", null));
- }
-
- @Test
- public void testGetMethodName3() {
- assertEquals("remove(int)",
- names.getMethodName("java/util/List", "remove", "(I)V", null));
- }
-
- @Test
- public void testGetMethodName4() {
- assertEquals("add(int, Object)", names.getMethodName("java/util/List",
- "add", "(ILjava/lang/Object;)V", null));
- }
-
- @Test
- public void testGetMethodName5() {
- assertEquals("sort(Object[])", names.getMethodName("java/util/Arrays",
- "sort", "([Ljava/lang/Object;)V", null));
- }
-
- @Test
- public void testGetMethodName6() {
- assertEquals("Object()",
- names.getMethodName("java/lang/Object", "<init>", "()V", null));
- }
-
- @Test
- public void testGetMethodName7() {
- assertEquals("static {...}", names.getMethodName(
- "com/example/SomeClass", "<clinit>", "()V", null));
- }
-
- @Test
- public void testGetMethodName8() {
- assertEquals("update(Map.Entry)", names.getMethodName(
- "com/example/SomeClass", "update", "(Ljava/util/Map$Entry;)V",
- null));
- }
-
- @Test
- public void testGetMethodName9() {
- assertEquals("{...}", names.getMethodName("com/example/SomeClass$1",
- "<init>", "()V", null));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link JavaNames}. + */ +public class JavaNamesTest { + + private ILanguageNames names; + + @Before + public void setup() { + names = new JavaNames(); + } + + @Test + public void testGetPackageName1() { + assertEquals("default", names.getPackageName("")); + } + + @Test + public void testGetPackageName2() { + assertEquals("java.lang", names.getPackageName("java/lang")); + } + + @Test + public void testGetClassName1() { + assertEquals("Main", names.getClassName("Main", null, null, null)); + } + + @Test + public void testGetClassName2() { + assertEquals("Object", + names.getClassName("java/lang/Object", null, null, null)); + } + + @Test + public void testGetClassName3() { + assertEquals("Map.Entry", + names.getClassName("java/util/Map$Entry", null, null, null)); + } + + @Test + public void testGetClassName4() { + assertEquals("Bar.new Object() {...}", names.getClassName( + "com/foo/Bar$1", null, "java/lang/Object", new String[0])); + } + + @Test + public void testGetClassName5() { + assertEquals("Bar.new ISample() {...}", names.getClassName( + "com/foo/Bar$1", null, "java/lang/Object", + new String[] { "org/foo/ISample" })); + } + + @Test + public void testGetClassName6() { + assertEquals("Bar.1", + names.getClassName("com/foo/Bar$1", null, null, null)); + } + + @Test + public void testGetClassName7() { + assertEquals("Strange.", + names.getClassName("com/foo/Strange$", null, null, null)); + } + + @Test + public void testGetQualifiedClassName1() { + assertEquals("Foo", names.getQualifiedClassName("Foo")); + } + + @Test + public void testGetQualifiedClassName2() { + assertEquals("java.lang.Object", + names.getQualifiedClassName("java/lang/Object")); + } + + @Test + public void testGetQualifiedClassName3() { + assertEquals("java.util.Map.Entry", + names.getQualifiedClassName("java/util/Map$Entry")); + } + + @Test + public void testGetMethodName1() { + assertEquals("wait()", + names.getMethodName("java/lang/Object", "wait", "()V", null)); + } + + @Test + public void testGetMethodName2() { + assertEquals("remove(Object)", + names.getMethodName("java/util/Collection", "remove", + "(Ljava/lang/Object;)V", null)); + } + + @Test + public void testGetMethodName3() { + assertEquals("remove(int)", + names.getMethodName("java/util/List", "remove", "(I)V", null)); + } + + @Test + public void testGetMethodName4() { + assertEquals("add(int, Object)", names.getMethodName("java/util/List", + "add", "(ILjava/lang/Object;)V", null)); + } + + @Test + public void testGetMethodName5() { + assertEquals("sort(Object[])", names.getMethodName("java/util/Arrays", + "sort", "([Ljava/lang/Object;)V", null)); + } + + @Test + public void testGetMethodName6() { + assertEquals("Object()", + names.getMethodName("java/lang/Object", "<init>", "()V", null)); + } + + @Test + public void testGetMethodName7() { + assertEquals("static {...}", names.getMethodName( + "com/example/SomeClass", "<clinit>", "()V", null)); + } + + @Test + public void testGetMethodName8() { + assertEquals("update(Map.Entry)", names.getMethodName( + "com/example/SomeClass", "update", "(Ljava/util/Map$Entry;)V", + null)); + } + + @Test + public void testGetMethodName9() { + assertEquals("{...}", names.getMethodName("com/example/SomeClass$1", + "<init>", "()V", null)); + } + +} 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 d6e492cb..5d51d2fa 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/MemoryMultiReportOutput.java +++ b/org.jacoco.report.test/src/org/jacoco/report/MemoryMultiReportOutput.java @@ -1,86 +1,86 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * In-memory report output for test purposes.
- */
-public class MemoryMultiReportOutput implements IMultiReportOutput {
-
- private final Map<String, ByteArrayOutputStream> files = new HashMap<String, ByteArrayOutputStream>();
-
- private final Set<String> open = new HashSet<String>();
-
- private boolean closed = false;
-
- public OutputStream createFile(final String path) throws IOException {
- assertFalse("Duplicate output " + path, files.containsKey(path));
- open.add(path);
- final ByteArrayOutputStream out = new ByteArrayOutputStream() {
- @Override
- public void close() throws IOException {
- open.remove(path);
- super.close();
- }
- };
- files.put(path, out);
- return out;
- }
-
- public void close() throws IOException {
- closed = true;
- }
-
- public void assertEmpty() {
- assertEquals(Collections.emptySet(), files.keySet());
- }
-
- public void assertFile(String path) {
- assertNotNull(String.format("Missing file %s. Actual files are %s.",
- path, files.keySet()), files.get(path));
- }
-
- public void assertSingleFile(String path) {
- assertEquals(Collections.singleton(path), files.keySet());
- }
-
- public byte[] getFile(String path) {
- assertFile(path);
- return files.get(path).toByteArray();
- }
-
- public InputStream getFileAsStream(String path) {
- return new ByteArrayInputStream(getFile(path));
- }
-
- public void assertAllClosed() {
- assertEquals(Collections.emptySet(), open);
- assertTrue(closed);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * In-memory report output for test purposes. + */ +public class MemoryMultiReportOutput implements IMultiReportOutput { + + private final Map<String, ByteArrayOutputStream> files = new HashMap<String, ByteArrayOutputStream>(); + + private final Set<String> open = new HashSet<String>(); + + private boolean closed = false; + + public OutputStream createFile(final String path) throws IOException { + assertFalse("Duplicate output " + path, files.containsKey(path)); + open.add(path); + final ByteArrayOutputStream out = new ByteArrayOutputStream() { + @Override + public void close() throws IOException { + open.remove(path); + super.close(); + } + }; + files.put(path, out); + return out; + } + + public void close() throws IOException { + closed = true; + } + + public void assertEmpty() { + assertEquals(Collections.emptySet(), files.keySet()); + } + + public void assertFile(String path) { + assertNotNull(String.format("Missing file %s. Actual files are %s.", + path, files.keySet()), files.get(path)); + } + + public void assertSingleFile(String path) { + assertEquals(Collections.singleton(path), files.keySet()); + } + + public byte[] getFile(String path) { + assertFile(path); + return files.get(path).toByteArray(); + } + + public InputStream getFileAsStream(String path) { + return new ByteArrayInputStream(getFile(path)); + } + + public void assertAllClosed() { + assertEquals(Collections.emptySet(), open); + assertTrue(closed); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/MemoryOutput.java b/org.jacoco.report.test/src/org/jacoco/report/MemoryOutput.java index 6e88e81e..883964d3 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/MemoryOutput.java +++ b/org.jacoco.report.test/src/org/jacoco/report/MemoryOutput.java @@ -1,42 +1,42 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * In-memory report output for test purposes.
- */
-public class MemoryOutput extends ByteArrayOutputStream {
-
- private boolean closed = false;
-
- @Override
- public void close() throws IOException {
- super.close();
- closed = true;
- }
-
- public InputStream getContentsAsStream() {
- return new ByteArrayInputStream(toByteArray());
- }
-
- public void assertClosed() {
- assertTrue(closed);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * In-memory report output for test purposes. + */ +public class MemoryOutput extends ByteArrayOutputStream { + + private boolean closed = false; + + @Override + public void close() throws IOException { + super.close(); + closed = true; + } + + public InputStream getContentsAsStream() { + return new ByteArrayInputStream(toByteArray()); + } + + public void assertClosed() { + assertTrue(closed); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/MultiReportVisitorTest.java b/org.jacoco.report.test/src/org/jacoco/report/MultiReportVisitorTest.java index c69b5903..c9669a72 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/MultiReportVisitorTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/MultiReportVisitorTest.java @@ -1,129 +1,129 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.jacoco.core.analysis.IBundleCoverage;
-import org.jacoco.core.analysis.IPackageCoverage;
-import org.jacoco.core.data.ExecutionData;
-import org.jacoco.core.data.SessionInfo;
-import org.jacoco.core.internal.analysis.BundleCoverageImpl;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link MultiReportVisitor}.
- */
-public class MultiReportVisitorTest {
-
- private static class MockVisitor extends MockGroupVisitor implements
- IReportVisitor {
-
- MockVisitor() {
- super("Report");
- }
-
- private boolean visitInfosCalled = false;
-
- private boolean visitEndCalled = false;
-
- public void visitInfo(List<SessionInfo> sessionInfos,
- Collection<ExecutionData> executionData) throws IOException {
- visitInfosCalled = true;
- }
-
- public void visitEnd() throws IOException {
- visitEndCalled = true;
- }
-
- @Override
- public String toString() {
- assertTrue("visitInfos() has not been called", visitInfosCalled);
- assertTrue("visitEnd() has not been called", visitEndCalled);
- return super.toString();
- }
-
- }
-
- private static class MockGroupVisitor implements IReportGroupVisitor {
-
- private final String name;
-
- private final List<MockGroupVisitor> children = new ArrayList<MockGroupVisitor>();
-
- MockGroupVisitor(String name) {
- this.name = name;
- }
-
- public void visitBundle(IBundleCoverage bundle,
- ISourceFileLocator locator) throws IOException {
- children.add(new MockGroupVisitor(bundle.getName()));
- }
-
- public IReportGroupVisitor visitGroup(String name) throws IOException {
- MockGroupVisitor child = new MockGroupVisitor(name);
- children.add(child);
- return child;
- }
-
- @Override
- public String toString() {
- return name + children;
- }
- }
-
- private IBundleCoverage createBundle(String name) {
- final Collection<IPackageCoverage> packages = Collections.emptyList();
- return new BundleCoverageImpl(name, packages);
- }
-
- private static final String MOCK_REPORT = "Report[g1[b1[], b2[]], g2[]]";
-
- private void createMockReport(IReportVisitor visitor) throws IOException {
- final List<SessionInfo> sessions = Collections.emptyList();
- final List<ExecutionData> executionData = Collections.emptyList();
- visitor.visitInfo(sessions, executionData);
- IReportGroupVisitor g1 = visitor.visitGroup("g1");
- g1.visitBundle(createBundle("b1"), null);
- g1.visitBundle(createBundle("b2"), null);
- visitor.visitGroup("g2");
- visitor.visitEnd();
- }
-
- @Test
- public void testMockFormatter() throws IOException {
- MockVisitor visitor = new MockVisitor();
- createMockReport(visitor);
- assertEquals(MOCK_REPORT, visitor.toString());
- }
-
- @Test
- public void testMultiFormatter() throws IOException {
- IReportVisitor mock1 = new MockVisitor();
- IReportVisitor mock2 = new MockVisitor();
- IReportVisitor mock3 = new MockVisitor();
- List<IReportVisitor> visitors = Arrays.asList(mock1, mock2, mock3);
- MultiReportVisitor multi = new MultiReportVisitor(visitors);
- createMockReport(multi);
- assertEquals(MOCK_REPORT, mock1.toString());
- assertEquals(MOCK_REPORT, mock2.toString());
- assertEquals(MOCK_REPORT, mock3.toString());
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.jacoco.core.analysis.IBundleCoverage; +import org.jacoco.core.analysis.IPackageCoverage; +import org.jacoco.core.data.ExecutionData; +import org.jacoco.core.data.SessionInfo; +import org.jacoco.core.internal.analysis.BundleCoverageImpl; +import org.junit.Test; + +/** + * Unit tests for {@link MultiReportVisitor}. + */ +public class MultiReportVisitorTest { + + private static class MockVisitor extends MockGroupVisitor implements + IReportVisitor { + + MockVisitor() { + super("Report"); + } + + private boolean visitInfosCalled = false; + + private boolean visitEndCalled = false; + + public void visitInfo(List<SessionInfo> sessionInfos, + Collection<ExecutionData> executionData) throws IOException { + visitInfosCalled = true; + } + + public void visitEnd() throws IOException { + visitEndCalled = true; + } + + @Override + public String toString() { + assertTrue("visitInfos() has not been called", visitInfosCalled); + assertTrue("visitEnd() has not been called", visitEndCalled); + return super.toString(); + } + + } + + private static class MockGroupVisitor implements IReportGroupVisitor { + + private final String name; + + private final List<MockGroupVisitor> children = new ArrayList<MockGroupVisitor>(); + + MockGroupVisitor(String name) { + this.name = name; + } + + public void visitBundle(IBundleCoverage bundle, + ISourceFileLocator locator) throws IOException { + children.add(new MockGroupVisitor(bundle.getName())); + } + + public IReportGroupVisitor visitGroup(String name) throws IOException { + MockGroupVisitor child = new MockGroupVisitor(name); + children.add(child); + return child; + } + + @Override + public String toString() { + return name + children; + } + } + + private IBundleCoverage createBundle(String name) { + final Collection<IPackageCoverage> packages = Collections.emptyList(); + return new BundleCoverageImpl(name, packages); + } + + private static final String MOCK_REPORT = "Report[g1[b1[], b2[]], g2[]]"; + + private void createMockReport(IReportVisitor visitor) throws IOException { + final List<SessionInfo> sessions = Collections.emptyList(); + final List<ExecutionData> executionData = Collections.emptyList(); + visitor.visitInfo(sessions, executionData); + IReportGroupVisitor g1 = visitor.visitGroup("g1"); + g1.visitBundle(createBundle("b1"), null); + g1.visitBundle(createBundle("b2"), null); + visitor.visitGroup("g2"); + visitor.visitEnd(); + } + + @Test + public void testMockFormatter() throws IOException { + MockVisitor visitor = new MockVisitor(); + createMockReport(visitor); + assertEquals(MOCK_REPORT, visitor.toString()); + } + + @Test + public void testMultiFormatter() throws IOException { + IReportVisitor mock1 = new MockVisitor(); + IReportVisitor mock2 = new MockVisitor(); + IReportVisitor mock3 = new MockVisitor(); + List<IReportVisitor> visitors = Arrays.asList(mock1, mock2, mock3); + MultiReportVisitor multi = new MultiReportVisitor(visitors); + createMockReport(multi); + assertEquals(MOCK_REPORT, mock1.toString()); + assertEquals(MOCK_REPORT, mock2.toString()); + assertEquals(MOCK_REPORT, mock3.toString()); + } +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/csv/CSVGroupHandlerTest.java b/org.jacoco.report.test/src/org/jacoco/report/csv/CSVGroupHandlerTest.java index 04b90cc4..b3d3be27 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/csv/CSVGroupHandlerTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/csv/CSVGroupHandlerTest.java @@ -1,70 +1,70 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.csv;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.BufferedReader;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import org.jacoco.report.IReportGroupVisitor;
-import org.jacoco.report.JavaNames;
-import org.jacoco.report.ReportStructureTestDriver;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link CSVGroupHandler}.
- */
-public class CSVGroupHandlerTest {
-
- private IReportGroupVisitor handler;
-
- private StringWriter result;
-
- private ReportStructureTestDriver driver;
-
- @Before
- public void setup() throws Exception {
- result = new StringWriter();
- final DelimitedWriter dw = new DelimitedWriter(result);
- final ClassRowWriter rw = new ClassRowWriter(dw, new JavaNames());
- handler = new CSVGroupHandler(rw);
- driver = new ReportStructureTestDriver();
- }
-
- @Test
- public void testVisitBundle() throws Exception {
- driver.sendBundle(handler);
- final BufferedReader reader = getResultReader();
- reader.readLine();
- assertEquals(
- "bundle,org.jacoco.example,FooClass,10,15,1,2,0,3,1,2,0,1",
- reader.readLine());
- }
-
- @Test
- public void testVisitGroup() throws Exception {
- driver.sendGroup(handler);
- final BufferedReader reader = getResultReader();
- reader.readLine();
- assertEquals(
- "group/bundle,org.jacoco.example,FooClass,10,15,1,2,0,3,1,2,0,1",
- reader.readLine());
- }
-
- private BufferedReader getResultReader() {
- return new BufferedReader(new StringReader(result.toString()));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.csv; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.StringReader; +import java.io.StringWriter; + +import org.jacoco.report.IReportGroupVisitor; +import org.jacoco.report.JavaNames; +import org.jacoco.report.ReportStructureTestDriver; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link CSVGroupHandler}. + */ +public class CSVGroupHandlerTest { + + private IReportGroupVisitor handler; + + private StringWriter result; + + private ReportStructureTestDriver driver; + + @Before + public void setup() throws Exception { + result = new StringWriter(); + final DelimitedWriter dw = new DelimitedWriter(result); + final ClassRowWriter rw = new ClassRowWriter(dw, new JavaNames()); + handler = new CSVGroupHandler(rw); + driver = new ReportStructureTestDriver(); + } + + @Test + public void testVisitBundle() throws Exception { + driver.sendBundle(handler); + final BufferedReader reader = getResultReader(); + reader.readLine(); + assertEquals( + "bundle,org.jacoco.example,FooClass,10,15,1,2,0,3,1,2,0,1", + reader.readLine()); + } + + @Test + public void testVisitGroup() throws Exception { + driver.sendGroup(handler); + final BufferedReader reader = getResultReader(); + reader.readLine(); + assertEquals( + "group/bundle,org.jacoco.example,FooClass,10,15,1,2,0,3,1,2,0,1", + reader.readLine()); + } + + private BufferedReader getResultReader() { + return new BufferedReader(new StringReader(result.toString())); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/csv/ClassRowWriterTest.java b/org.jacoco.report.test/src/org/jacoco/report/csv/ClassRowWriterTest.java index bde27480..df205c40 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/csv/ClassRowWriterTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/csv/ClassRowWriterTest.java @@ -1,94 +1,94 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.csv;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.BufferedReader;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import org.jacoco.core.analysis.IClassCoverage;
-import org.jacoco.core.internal.analysis.ClassCoverageImpl;
-import org.jacoco.core.internal.analysis.CounterImpl;
-import org.jacoco.report.ILanguageNames;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link ClassRowWriter}.
- */
-public class ClassRowWriterTest {
-
- private StringWriter result;
-
- private ClassRowWriter writer;
-
- @Before
- public void setup() throws Exception {
- ILanguageNames names = new ILanguageNames() {
- public String getClassName(String vmname, String vmsignature,
- String vmsuperclass, String[] vminterfaces) {
- return vmname;
- }
-
- public String getPackageName(String vmname) {
- return vmname;
- }
-
- public String getQualifiedClassName(String vmname) {
- throw new AssertionError();
- }
-
- public String getMethodName(String vmclassname,
- String vmmethodname, String vmdesc, String vmsignature) {
- throw new AssertionError();
- }
- };
- result = new StringWriter();
- writer = new ClassRowWriter(new DelimitedWriter(result), names);
- }
-
- @Test
- public void TestHeader() throws Exception {
- BufferedReader reader = getResultReader();
- assertEquals(
- "GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED",
- reader.readLine());
- }
-
- @Test
- public void TestRow() throws Exception {
- IClassCoverage node = new ClassCoverageImpl("test/package/Foo", 123,
- null, "java/lang/Object", null) {
- {
- instructionCounter = CounterImpl.getInstance(1, 11);
- branchCounter = CounterImpl.getInstance(2, 22);
- lineCounter = CounterImpl.getInstance(3, 33);
- complexityCounter = CounterImpl.getInstance(4, 44);
- methodCounter = CounterImpl.getInstance(5, 55);
- classCounter = CounterImpl.getInstance(6, 66);
- }
- };
- writer.writeRow("group", "test/package", node);
- BufferedReader reader = getResultReader();
- reader.readLine();
- assertEquals(
- "group,test/package,test/package/Foo,1,11,2,22,3,33,4,44,5,55",
- reader.readLine());
- }
-
- private BufferedReader getResultReader() {
- return new BufferedReader(new StringReader(result.toString()));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.csv; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.StringReader; +import java.io.StringWriter; + +import org.jacoco.core.analysis.IClassCoverage; +import org.jacoco.core.internal.analysis.ClassCoverageImpl; +import org.jacoco.core.internal.analysis.CounterImpl; +import org.jacoco.report.ILanguageNames; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link ClassRowWriter}. + */ +public class ClassRowWriterTest { + + private StringWriter result; + + private ClassRowWriter writer; + + @Before + public void setup() throws Exception { + ILanguageNames names = new ILanguageNames() { + public String getClassName(String vmname, String vmsignature, + String vmsuperclass, String[] vminterfaces) { + return vmname; + } + + public String getPackageName(String vmname) { + return vmname; + } + + public String getQualifiedClassName(String vmname) { + throw new AssertionError(); + } + + public String getMethodName(String vmclassname, + String vmmethodname, String vmdesc, String vmsignature) { + throw new AssertionError(); + } + }; + result = new StringWriter(); + writer = new ClassRowWriter(new DelimitedWriter(result), names); + } + + @Test + public void TestHeader() throws Exception { + BufferedReader reader = getResultReader(); + assertEquals( + "GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED", + reader.readLine()); + } + + @Test + public void TestRow() throws Exception { + IClassCoverage node = new ClassCoverageImpl("test/package/Foo", 123, + null, "java/lang/Object", null) { + { + instructionCounter = CounterImpl.getInstance(1, 11); + branchCounter = CounterImpl.getInstance(2, 22); + lineCounter = CounterImpl.getInstance(3, 33); + complexityCounter = CounterImpl.getInstance(4, 44); + methodCounter = CounterImpl.getInstance(5, 55); + classCounter = CounterImpl.getInstance(6, 66); + } + }; + writer.writeRow("group", "test/package", node); + BufferedReader reader = getResultReader(); + reader.readLine(); + assertEquals( + "group,test/package,test/package/Foo,1,11,2,22,3,33,4,44,5,55", + reader.readLine()); + } + + private BufferedReader getResultReader() { + return new BufferedReader(new StringReader(result.toString())); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/csv/DelimitedWriterTest.java b/org.jacoco.report.test/src/org/jacoco/report/csv/DelimitedWriterTest.java index f0371166..f1fdcd05 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/csv/DelimitedWriterTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/csv/DelimitedWriterTest.java @@ -1,118 +1,118 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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:
- * Brock Janiczak - initial API and implementation
- *
- *******************************************************************************/
-package org.jacoco.report.csv;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link DelimitedWriter}
- */
-public class DelimitedWriterTest {
-
- private StringWriter result;
- private DelimitedWriter writer;
-
- private static final String NEW_LINE = System.getProperty("line.separator");
-
- @Before
- public void setUp() {
- result = new StringWriter();
- writer = new DelimitedWriter(result);
- }
-
- @Test
- public void testNoWrites() throws IOException {
- assertResult("");
- }
-
- @Test
- public void testSingleField() throws IOException {
- writer.write("test");
- assertResult("test");
- }
-
- @Test
- public void testFieldContainingDelimiter() throws IOException {
- writer.write("value,1");
- assertResult("\"value,1\"");
- }
-
- @Test
- public void testFieldContainingDelimiterAndQuote() throws IOException {
- writer.write("\",\"");
- assertResult("\"\"\",\"\"\"");
- }
-
- @Test
- public void testWriteEmptyHeader() throws IOException {
- writer.write(new String[] {});
- assertResult("");
- }
-
- @Test
- public void testWriteHeader() throws IOException {
- writer.write("header1", "header2", "header3");
- assertResult("header1,header2,header3");
- }
-
- @Test
- public void testMultipleFieldsOnOneLine() throws IOException {
- writer.write("test1");
- writer.write("test2");
- assertResult("test1,test2");
- }
-
- @Test
- public void testMultipleFieldsOnMultipleLines() throws IOException {
- writer.write("test1");
- writer.write("test2");
- writer.nextLine();
- writer.write("test3");
- writer.write("test4");
- assertResult("test1,test2" + NEW_LINE + "test3,test4");
- }
-
- @Test
- public void testAutoEscapedField() throws IOException {
- writer.write("\"\"");
- assertResult("\"\"\"\"\"\"");
- }
-
- @Test
- public void testWordWithSpace() throws IOException {
- writer.write("space test");
- assertResult("space test");
- }
-
- @Test
- public void testInt() throws IOException {
- writer.write(-123000);
- assertResult("-123000");
- }
-
- @Test
- public void testInts() throws IOException {
- writer.write(1, 20, 300);
- assertResult("1,20,300");
- }
-
- private void assertResult(String expected) throws IOException {
- writer.close();
- assertEquals(expected, result.toString());
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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: + * Brock Janiczak - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.report.csv; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.StringWriter; + +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link DelimitedWriter} + */ +public class DelimitedWriterTest { + + private StringWriter result; + private DelimitedWriter writer; + + private static final String NEW_LINE = System.getProperty("line.separator"); + + @Before + public void setUp() { + result = new StringWriter(); + writer = new DelimitedWriter(result); + } + + @Test + public void testNoWrites() throws IOException { + assertResult(""); + } + + @Test + public void testSingleField() throws IOException { + writer.write("test"); + assertResult("test"); + } + + @Test + public void testFieldContainingDelimiter() throws IOException { + writer.write("value,1"); + assertResult("\"value,1\""); + } + + @Test + public void testFieldContainingDelimiterAndQuote() throws IOException { + writer.write("\",\""); + assertResult("\"\"\",\"\"\""); + } + + @Test + public void testWriteEmptyHeader() throws IOException { + writer.write(new String[] {}); + assertResult(""); + } + + @Test + public void testWriteHeader() throws IOException { + writer.write("header1", "header2", "header3"); + assertResult("header1,header2,header3"); + } + + @Test + public void testMultipleFieldsOnOneLine() throws IOException { + writer.write("test1"); + writer.write("test2"); + assertResult("test1,test2"); + } + + @Test + public void testMultipleFieldsOnMultipleLines() throws IOException { + writer.write("test1"); + writer.write("test2"); + writer.nextLine(); + writer.write("test3"); + writer.write("test4"); + assertResult("test1,test2" + NEW_LINE + "test3,test4"); + } + + @Test + public void testAutoEscapedField() throws IOException { + writer.write("\"\""); + assertResult("\"\"\"\"\"\""); + } + + @Test + public void testWordWithSpace() throws IOException { + writer.write("space test"); + assertResult("space test"); + } + + @Test + public void testInt() throws IOException { + writer.write(-123000); + assertResult("-123000"); + } + + @Test + public void testInts() throws IOException { + writer.write(1, 20, 300); + assertResult("1,20,300"); + } + + private void assertResult(String expected) throws IOException { + writer.close(); + assertEquals(expected, result.toString()); + } +} 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 index be810306..6b21b68b 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/NormalizedFileNamesTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/NormalizedFileNamesTest.java @@ -1,76 +1,76 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 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 testSameInstance() {
- // If no normalization is required we should get the same instance.
- String id = new String("Example.html");
- assertSame(id, nfn.getFileName(id));
- assertSame(id, nfn.getFileName(new String("Example.html")));
- }
-
- @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"));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 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 testSameInstance() { + // If no normalization is required we should get the same instance. + String id = new String("Example.html"); + assertSame(id, nfn.getFileName(id)); + assertSame(id, nfn.getFileName(new String("Example.html"))); + } + + @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 index bc597fbf..8b82e14b 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/ReportOutputFolderTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/ReportOutputFolderTest.java @@ -1,106 +1,106 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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");
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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/HTMLDocumentTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLDocumentTest.java index 7257d783..c29be43b 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLDocumentTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLDocumentTest.java @@ -1,85 +1,85 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 static org.junit.Assert.assertEquals;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-
-import org.junit.Test;
-
-/**
- * Unit tests for {@link HTMLDocument}.
- */
-public class HTMLDocumentTest {
-
- @Test
- public void testWriter() throws IOException {
- StringWriter buffer = new StringWriter();
- new HTMLDocument(buffer, "UTF-8").close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
- + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>",
- buffer.toString());
- }
-
- @Test
- public void testStream() throws IOException {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- new HTMLDocument(buffer, "UTF-8").close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
- + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>",
- buffer.toString("UTF-8"));
- }
-
- @Test
- public void testHead() throws IOException {
- StringWriter buffer = new StringWriter();
- final HTMLDocument doc = new HTMLDocument(buffer, "UTF-8");
- doc.head();
- doc.close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
- + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head/></html>",
- buffer.toString());
- }
-
- @Test
- public void testBody() throws IOException {
- StringWriter buffer = new StringWriter();
- final HTMLDocument doc = new HTMLDocument(buffer, "UTF-8");
- doc.body();
- doc.close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
- + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><body/></html>",
- buffer.toString());
- }
-
- @Test
- public void testMinimalHTMLDocument() throws Exception {
- StringWriter buffer = new StringWriter();
- final HTMLDocument doc = new HTMLDocument(buffer, "UTF-8");
- doc.head().title();
- doc.body();
- doc.close();
- new HTMLSupport().parse(buffer.toString());
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringWriter; + +import org.junit.Test; + +/** + * Unit tests for {@link HTMLDocument}. + */ +public class HTMLDocumentTest { + + @Test + public void testWriter() throws IOException { + StringWriter buffer = new StringWriter(); + new HTMLDocument(buffer, "UTF-8").close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" + + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>", + buffer.toString()); + } + + @Test + public void testStream() throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + new HTMLDocument(buffer, "UTF-8").close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" + + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>", + buffer.toString("UTF-8")); + } + + @Test + public void testHead() throws IOException { + StringWriter buffer = new StringWriter(); + final HTMLDocument doc = new HTMLDocument(buffer, "UTF-8"); + doc.head(); + doc.close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" + + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head/></html>", + buffer.toString()); + } + + @Test + public void testBody() throws IOException { + StringWriter buffer = new StringWriter(); + final HTMLDocument doc = new HTMLDocument(buffer, "UTF-8"); + doc.body(); + doc.close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" + + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><body/></html>", + buffer.toString()); + } + + @Test + public void testMinimalHTMLDocument() throws Exception { + StringWriter buffer = new StringWriter(); + final HTMLDocument doc = new HTMLDocument(buffer, "UTF-8"); + doc.head().title(); + doc.body(); + doc.close(); + new HTMLSupport().parse(buffer.toString()); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLElementTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLElementTest.java index f05285c8..ce663396 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLElementTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLElementTest.java @@ -1,241 +1,241 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link HTMLElement}.
- */
-public class HTMLElementTest {
-
- private StringWriter buffer;
-
- private HTMLElement root;
-
- @Before
- public void setUp() throws IOException {
- buffer = new StringWriter();
- root = new HTMLElement(buffer, "root") {
- {
- beginOpenTag();
- }
- };
- }
-
- @Test
- public void testMeta() throws IOException {
- root.meta("key", "value");
- root.close();
- assertEquals(
- "<root><meta http-equiv=\"key\" content=\"value\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testLink() throws IOException {
- root.link("stylesheet", "style.css", "text/css");
- root.close();
- assertEquals(
- "<root><link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testTitle() throws IOException {
- root.title();
- root.close();
- assertEquals("<root><title/></root>", buffer.toString());
- }
-
- @Test
- public void testH1() throws IOException {
- root.h1();
- root.close();
- assertEquals("<root><h1/></root>", buffer.toString());
- }
-
- @Test
- public void testP() throws IOException {
- root.p();
- root.close();
- assertEquals("<root><p/></root>", buffer.toString());
- }
-
- @Test
- public void testSpan1() throws IOException {
- root.span();
- root.close();
- assertEquals("<root><span/></root>", buffer.toString());
- }
-
- @Test
- public void testSpan2() throws IOException {
- root.span("abc");
- root.close();
- assertEquals("<root><span class=\"abc\"/></root>", buffer.toString());
- }
-
- @Test
- public void testSpan3() throws IOException {
- root.span("abc", "xy");
- root.close();
- assertEquals("<root><span class=\"abc\" id=\"xy\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testPre() throws IOException {
- root.pre("mystyle");
- root.close();
- assertEquals("<root><pre class=\"mystyle\"/></root>", buffer.toString());
- }
-
- @Test
- public void testDiv() throws IOException {
- root.div("mystyle");
- root.close();
- assertEquals("<root><div class=\"mystyle\"/></root>", buffer.toString());
- }
-
- @Test
- public void testCode() throws IOException {
- root.code().text("0xCAFEBABE");
- root.close();
- assertEquals("<root><code>0xCAFEBABE</code></root>", buffer.toString());
- }
-
- @Test
- public void testA1() throws IOException {
- root.a("http://www.jacoco.org/");
- root.close();
- assertEquals("<root><a href=\"http://www.jacoco.org/\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testA2() throws IOException {
- root.a("http://www.jacoco.org/", "extern");
- root.close();
- assertEquals(
- "<root><a href=\"http://www.jacoco.org/\" class=\"extern\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testALinkable1() throws IOException {
- root.a(new LinkableStub(null, "here", null), null);
- root.close();
- assertEquals("<root><span>here</span></root>", buffer.toString());
- }
-
- @Test
- public void testALinkable2() throws IOException {
- root.a(new LinkableStub(null, "here", "blue"), null);
- root.close();
- assertEquals("<root><span class=\"blue\">here</span></root>",
- buffer.toString());
- }
-
- @Test
- public void testALinkable3() throws IOException {
- root.a(new LinkableStub("index.html", "here", null), null);
- root.close();
- assertEquals("<root><a href=\"index.html\">here</a></root>",
- buffer.toString());
- }
-
- @Test
- public void testALinkable4() throws IOException {
- root.a(new LinkableStub("index.html", "here", "red"), null);
- root.close();
- assertEquals(
- "<root><a href=\"index.html\" class=\"red\">here</a></root>",
- buffer.toString());
- }
-
- @Test
- public void testTable() throws IOException {
- root.table("tablestyle");
- root.close();
- assertEquals(
- "<root><table class=\"tablestyle\" cellspacing=\"0\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testThead() throws IOException {
- root.thead();
- root.close();
- assertEquals("<root><thead/></root>", buffer.toString());
- }
-
- @Test
- public void testTfoot() throws IOException {
- root.tfoot();
- root.close();
- assertEquals("<root><tfoot/></root>", buffer.toString());
- }
-
- @Test
- public void testTbody() throws IOException {
- root.tbody();
- root.close();
- assertEquals("<root><tbody/></root>", buffer.toString());
- }
-
- @Test
- public void testTr() throws IOException {
- root.tr();
- root.close();
- assertEquals("<root><tr/></root>", buffer.toString());
- }
-
- @Test
- public void testTd1() throws IOException {
- root.td();
- root.close();
- assertEquals("<root><td/></root>", buffer.toString());
- }
-
- @Test
- public void testTd2() throws IOException {
- root.td("mystyle");
- root.close();
- assertEquals("<root><td class=\"mystyle\"/></root>", buffer.toString());
- }
-
- @Test
- public void testImg() throws IOException {
- root.img("sample.gif", 16, 32, "Hello");
- root.close();
- assertEquals(
- "<root><img src=\"sample.gif\" width=\"16\" height=\"32\" title=\"Hello\" alt=\"Hello\"/></root>",
- buffer.toString());
- }
-
- @Test
- public void testScript() throws IOException {
- root.script("text/javascript", "file.js");
- root.close();
- assertEquals(
- "<root><script type=\"text/javascript\" src=\"file.js\"></script></root>",
- buffer.toString());
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.StringWriter; + +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link HTMLElement}. + */ +public class HTMLElementTest { + + private StringWriter buffer; + + private HTMLElement root; + + @Before + public void setUp() throws IOException { + buffer = new StringWriter(); + root = new HTMLElement(buffer, "root") { + { + beginOpenTag(); + } + }; + } + + @Test + public void testMeta() throws IOException { + root.meta("key", "value"); + root.close(); + assertEquals( + "<root><meta http-equiv=\"key\" content=\"value\"/></root>", + buffer.toString()); + } + + @Test + public void testLink() throws IOException { + root.link("stylesheet", "style.css", "text/css"); + root.close(); + assertEquals( + "<root><link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\"/></root>", + buffer.toString()); + } + + @Test + public void testTitle() throws IOException { + root.title(); + root.close(); + assertEquals("<root><title/></root>", buffer.toString()); + } + + @Test + public void testH1() throws IOException { + root.h1(); + root.close(); + assertEquals("<root><h1/></root>", buffer.toString()); + } + + @Test + public void testP() throws IOException { + root.p(); + root.close(); + assertEquals("<root><p/></root>", buffer.toString()); + } + + @Test + public void testSpan1() throws IOException { + root.span(); + root.close(); + assertEquals("<root><span/></root>", buffer.toString()); + } + + @Test + public void testSpan2() throws IOException { + root.span("abc"); + root.close(); + assertEquals("<root><span class=\"abc\"/></root>", buffer.toString()); + } + + @Test + public void testSpan3() throws IOException { + root.span("abc", "xy"); + root.close(); + assertEquals("<root><span class=\"abc\" id=\"xy\"/></root>", + buffer.toString()); + } + + @Test + public void testPre() throws IOException { + root.pre("mystyle"); + root.close(); + assertEquals("<root><pre class=\"mystyle\"/></root>", buffer.toString()); + } + + @Test + public void testDiv() throws IOException { + root.div("mystyle"); + root.close(); + assertEquals("<root><div class=\"mystyle\"/></root>", buffer.toString()); + } + + @Test + public void testCode() throws IOException { + root.code().text("0xCAFEBABE"); + root.close(); + assertEquals("<root><code>0xCAFEBABE</code></root>", buffer.toString()); + } + + @Test + public void testA1() throws IOException { + root.a("http://www.jacoco.org/"); + root.close(); + assertEquals("<root><a href=\"http://www.jacoco.org/\"/></root>", + buffer.toString()); + } + + @Test + public void testA2() throws IOException { + root.a("http://www.jacoco.org/", "extern"); + root.close(); + assertEquals( + "<root><a href=\"http://www.jacoco.org/\" class=\"extern\"/></root>", + buffer.toString()); + } + + @Test + public void testALinkable1() throws IOException { + root.a(new LinkableStub(null, "here", null), null); + root.close(); + assertEquals("<root><span>here</span></root>", buffer.toString()); + } + + @Test + public void testALinkable2() throws IOException { + root.a(new LinkableStub(null, "here", "blue"), null); + root.close(); + assertEquals("<root><span class=\"blue\">here</span></root>", + buffer.toString()); + } + + @Test + public void testALinkable3() throws IOException { + root.a(new LinkableStub("index.html", "here", null), null); + root.close(); + assertEquals("<root><a href=\"index.html\">here</a></root>", + buffer.toString()); + } + + @Test + public void testALinkable4() throws IOException { + root.a(new LinkableStub("index.html", "here", "red"), null); + root.close(); + assertEquals( + "<root><a href=\"index.html\" class=\"red\">here</a></root>", + buffer.toString()); + } + + @Test + public void testTable() throws IOException { + root.table("tablestyle"); + root.close(); + assertEquals( + "<root><table class=\"tablestyle\" cellspacing=\"0\"/></root>", + buffer.toString()); + } + + @Test + public void testThead() throws IOException { + root.thead(); + root.close(); + assertEquals("<root><thead/></root>", buffer.toString()); + } + + @Test + public void testTfoot() throws IOException { + root.tfoot(); + root.close(); + assertEquals("<root><tfoot/></root>", buffer.toString()); + } + + @Test + public void testTbody() throws IOException { + root.tbody(); + root.close(); + assertEquals("<root><tbody/></root>", buffer.toString()); + } + + @Test + public void testTr() throws IOException { + root.tr(); + root.close(); + assertEquals("<root><tr/></root>", buffer.toString()); + } + + @Test + public void testTd1() throws IOException { + root.td(); + root.close(); + assertEquals("<root><td/></root>", buffer.toString()); + } + + @Test + public void testTd2() throws IOException { + root.td("mystyle"); + root.close(); + assertEquals("<root><td class=\"mystyle\"/></root>", buffer.toString()); + } + + @Test + public void testImg() throws IOException { + root.img("sample.gif", 16, 32, "Hello"); + root.close(); + assertEquals( + "<root><img src=\"sample.gif\" width=\"16\" height=\"32\" title=\"Hello\" alt=\"Hello\"/></root>", + buffer.toString()); + } + + @Test + public void testScript() throws IOException { + root.script("text/javascript", "file.js"); + root.close(); + assertEquals( + "<root><script type=\"text/javascript\" src=\"file.js\"></script></root>", + buffer.toString()); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLSupport.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLSupport.java index fdae38c8..ade776b2 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLSupport.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/HTMLSupport.java @@ -1,27 +1,27 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 javax.xml.parsers.ParserConfigurationException;
-
-import org.jacoco.report.internal.xml.XMLSupport;
-
-/**
- * Support for verifying XHTML documents.
- */
-public class HTMLSupport extends XMLSupport {
-
- public HTMLSupport() throws ParserConfigurationException {
- super(HTMLSupport.class);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 javax.xml.parsers.ParserConfigurationException; + +import org.jacoco.report.internal.xml.XMLSupport; + +/** + * Support for verifying XHTML documents. + */ +public class HTMLSupport extends XMLSupport { + + public HTMLSupport() throws ParserConfigurationException { + super(HTMLSupport.class); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java index 7cad96c2..b4ef9d71 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java @@ -1,81 +1,81 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 org.jacoco.core.analysis.IClassCoverage;
-import org.jacoco.core.internal.analysis.ClassCoverageImpl;
-import org.jacoco.core.internal.analysis.MethodCoverageImpl;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link ClassPage}.
- */
-public class ClassPageTest extends PageTestBase {
-
- private ClassCoverageImpl node;
-
- private ClassPage page;
-
- @Before
- @Override
- public void setup() throws Exception {
- super.setup();
- node = new ClassCoverageImpl("org/jacoco/example/Foo", 123, null,
- "java/lang/Object", null);
- node.addMethod(new MethodCoverageImpl("a", "()V", null));
- node.addMethod(new MethodCoverageImpl("b", "()V", null));
- node.addMethod(new MethodCoverageImpl("c", "()V", null));
- }
-
- @Test
- public void testContents() throws Exception {
- page = new ClassPage(node, null, null, rootFolder, context);
- page.render();
-
- final Document doc = support.parse(output.getFile("Foo.html"));
- assertEquals("el_method", support.findStr(doc,
- "/html/body/table[1]/tbody/tr[1]/td[1]/span/@class"));
- assertEquals("a()", support.findStr(doc,
- "/html/body/table[1]/tbody/tr[1]/td[1]/span"));
- assertEquals("b()", support.findStr(doc,
- "/html/body/table[1]/tbody/tr[2]/td[1]/span"));
- assertEquals("c()", support.findStr(doc,
- "/html/body/table[1]/tbody/tr[3]/td[1]/span"));
- }
-
- @Test
- public void testGetFileName() throws IOException {
- page = new ClassPage(node, null, null, rootFolder, context);
- assertEquals("Foo.html", page.getFileName());
- }
-
- @Test
- public void testGetFileNameDefault() throws IOException {
- IClassCoverage defaultNode = new ClassCoverageImpl("Foo", 123, null,
- "java/lang/Object", null);
- page = new ClassPage(defaultNode, null, null, rootFolder, context);
- assertEquals("Foo.html", page.getFileName());
- }
-
- @Test
- public void testGetLinkLabel() throws IOException {
- page = new ClassPage(node, null, null, rootFolder, context);
- assertEquals("Foo", page.getLinkLabel());
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 org.jacoco.core.analysis.IClassCoverage; +import org.jacoco.core.internal.analysis.ClassCoverageImpl; +import org.jacoco.core.internal.analysis.MethodCoverageImpl; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link ClassPage}. + */ +public class ClassPageTest extends PageTestBase { + + private ClassCoverageImpl node; + + private ClassPage page; + + @Before + @Override + public void setup() throws Exception { + super.setup(); + node = new ClassCoverageImpl("org/jacoco/example/Foo", 123, null, + "java/lang/Object", null); + node.addMethod(new MethodCoverageImpl("a", "()V", null)); + node.addMethod(new MethodCoverageImpl("b", "()V", null)); + node.addMethod(new MethodCoverageImpl("c", "()V", null)); + } + + @Test + public void testContents() throws Exception { + page = new ClassPage(node, null, null, rootFolder, context); + page.render(); + + final Document doc = support.parse(output.getFile("Foo.html")); + assertEquals("el_method", support.findStr(doc, + "/html/body/table[1]/tbody/tr[1]/td[1]/span/@class")); + assertEquals("a()", support.findStr(doc, + "/html/body/table[1]/tbody/tr[1]/td[1]/span")); + assertEquals("b()", support.findStr(doc, + "/html/body/table[1]/tbody/tr[2]/td[1]/span")); + assertEquals("c()", support.findStr(doc, + "/html/body/table[1]/tbody/tr[3]/td[1]/span")); + } + + @Test + public void testGetFileName() throws IOException { + page = new ClassPage(node, null, null, rootFolder, context); + assertEquals("Foo.html", page.getFileName()); + } + + @Test + public void testGetFileNameDefault() throws IOException { + IClassCoverage defaultNode = new ClassCoverageImpl("Foo", 123, null, + "java/lang/Object", null); + page = new ClassPage(defaultNode, null, null, rootFolder, context); + assertEquals("Foo.html", page.getFileName()); + } + + @Test + public void testGetLinkLabel() throws IOException { + page = new ClassPage(node, null, null, rootFolder, context); + assertEquals("Foo", page.getLinkLabel()); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/MethodItemTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/MethodItemTest.java index 765204cd..61bc9368 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/MethodItemTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/MethodItemTest.java @@ -1,89 +1,89 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.assertNull;
-import static org.junit.Assert.assertSame;
-
-import org.jacoco.core.internal.analysis.CounterImpl;
-import org.jacoco.core.internal.analysis.MethodCoverageImpl;
-import org.jacoco.report.internal.ReportOutputFolder;
-import org.jacoco.report.internal.html.ILinkable;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link MethodItem}.
- */
-public class MethodItemTest {
-
- private MethodCoverageImpl node;
-
- @Before
- public void setup() {
- node = new MethodCoverageImpl("test", "()V", null);
- }
-
- @Test
- public void testGetNode() {
- final MethodItem item = new MethodItem(node, "test()", null);
- assertSame(node, item.getNode());
- }
-
- @Test
- public void testGetLinkLabel() {
- final MethodItem item = new MethodItem(node, "test()", null);
- assertEquals("test()", item.getLinkLabel());
- }
-
- @Test
- public void testGetLinkStyle() {
- final MethodItem item = new MethodItem(node, "test()", null);
- assertEquals("el_method", item.getLinkStyle());
- }
-
- @Test
- public void testGetLinkNone() {
- final MethodItem item = new MethodItem(node, "test()", null);
- assertNull(item.getLink(null));
- }
-
- @Test
- public void testGetLink() {
- final MethodItem item = new MethodItem(node, "test()", new SourceLink());
- assertEquals("../Source.java", item.getLink(null));
- }
-
- @Test
- public void testGetLinkWithLine() {
- node.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 15);
- final MethodItem item = new MethodItem(node, "test()", new SourceLink());
- assertEquals("../Source.java#L15", item.getLink(null));
- }
-
- private static class SourceLink implements ILinkable {
-
- public String getLinkStyle() {
- return "el_source";
- }
-
- public String getLinkLabel() {
- return "Source.java";
- }
-
- public String getLink(ReportOutputFolder base) {
- return "../Source.java";
- }
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.assertNull; +import static org.junit.Assert.assertSame; + +import org.jacoco.core.internal.analysis.CounterImpl; +import org.jacoco.core.internal.analysis.MethodCoverageImpl; +import org.jacoco.report.internal.ReportOutputFolder; +import org.jacoco.report.internal.html.ILinkable; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link MethodItem}. + */ +public class MethodItemTest { + + private MethodCoverageImpl node; + + @Before + public void setup() { + node = new MethodCoverageImpl("test", "()V", null); + } + + @Test + public void testGetNode() { + final MethodItem item = new MethodItem(node, "test()", null); + assertSame(node, item.getNode()); + } + + @Test + public void testGetLinkLabel() { + final MethodItem item = new MethodItem(node, "test()", null); + assertEquals("test()", item.getLinkLabel()); + } + + @Test + public void testGetLinkStyle() { + final MethodItem item = new MethodItem(node, "test()", null); + assertEquals("el_method", item.getLinkStyle()); + } + + @Test + public void testGetLinkNone() { + final MethodItem item = new MethodItem(node, "test()", null); + assertNull(item.getLink(null)); + } + + @Test + public void testGetLink() { + final MethodItem item = new MethodItem(node, "test()", new SourceLink()); + assertEquals("../Source.java", item.getLink(null)); + } + + @Test + public void testGetLinkWithLine() { + node.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 15); + final MethodItem item = new MethodItem(node, "test()", new SourceLink()); + assertEquals("../Source.java#L15", item.getLink(null)); + } + + private static class SourceLink implements ILinkable { + + public String getLinkStyle() { + return "el_source"; + } + + public String getLinkLabel() { + return "Source.java"; + } + + public String getLink(ReportOutputFolder base) { + return "../Source.java"; + } + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java index c211a23f..00e6d341 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/NodePageTest.java @@ -1,81 +1,81 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.assertSame;
-
-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.internal.html.HTMLElement;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link NodePage}.
- */
-public class NodePageTest extends PageTestBase {
-
- private CoverageNodeImpl node;
-
- private NodePage<ICoverageNode> page;
-
- private class TestNodePage extends NodePage<ICoverageNode> {
-
- protected TestNodePage(ICoverageNode node, ReportPage parent) {
- super(node, parent, rootFolder, NodePageTest.this.context);
- }
-
- @Override
- protected void content(HTMLElement body) throws IOException {
- }
-
- @Override
- protected String getFileName() {
- return "index.html";
- }
-
- }
-
- @Before
- @Override
- public void setup() throws Exception {
- super.setup();
- node = new CoverageNodeImpl(ElementType.GROUP, "Test");
- page = new TestNodePage(node, null);
- }
-
- @Test
- public void testGetNode() throws IOException {
- assertSame(node, page.getNode());
- }
-
- @Test
- public void testGetLinkLabel() throws IOException {
- assertEquals("Test", page.getLinkLabel());
- }
-
- @Test
- public void testGetLinkStyle1() throws IOException {
- assertEquals("el_report", page.getLinkStyle());
- }
-
- @Test
- public void testGetLinkStyle2() throws IOException {
- final TestNodePage group = new TestNodePage(node, page);
- assertEquals("el_group", group.getLinkStyle());
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.assertSame; + +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.internal.html.HTMLElement; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link NodePage}. + */ +public class NodePageTest extends PageTestBase { + + private CoverageNodeImpl node; + + private NodePage<ICoverageNode> page; + + private class TestNodePage extends NodePage<ICoverageNode> { + + protected TestNodePage(ICoverageNode node, ReportPage parent) { + super(node, parent, rootFolder, NodePageTest.this.context); + } + + @Override + protected void content(HTMLElement body) throws IOException { + } + + @Override + protected String getFileName() { + return "index.html"; + } + + } + + @Before + @Override + public void setup() throws Exception { + super.setup(); + node = new CoverageNodeImpl(ElementType.GROUP, "Test"); + page = new TestNodePage(node, null); + } + + @Test + public void testGetNode() throws IOException { + assertSame(node, page.getNode()); + } + + @Test + public void testGetLinkLabel() throws IOException { + assertEquals("Test", page.getLinkLabel()); + } + + @Test + public void testGetLinkStyle1() throws IOException { + assertEquals("el_report", page.getLinkStyle()); + } + + @Test + public void testGetLinkStyle2() throws IOException { + final TestNodePage group = new TestNodePage(node, page); + assertEquals("el_group", group.getLinkStyle()); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PageTestBase.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PageTestBase.java index 534b101d..56705a8d 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PageTestBase.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/PageTestBase.java @@ -1,99 +1,99 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 java.io.IOException;
-import java.util.Locale;
-
-import org.jacoco.report.ILanguageNames;
-import org.jacoco.report.JavaNames;
-import org.jacoco.report.MemoryMultiReportOutput;
-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;
-import org.jacoco.report.internal.html.table.LabelColumn;
-import org.jacoco.report.internal.html.table.Table;
-import org.junit.After;
-
-/**
- * Unit tests for {@link ReportPage}.
- */
-public abstract class PageTestBase {
-
- protected MemoryMultiReportOutput output;
-
- protected ReportOutputFolder rootFolder;
-
- protected IHTMLReportContext context;
-
- protected HTMLSupport support;
-
- protected void setup() throws Exception {
- output = new MemoryMultiReportOutput();
- rootFolder = new ReportOutputFolder(output);
- final Resources resources = new Resources(rootFolder);
- final Table table = new Table();
- table.add("Element", null, new LabelColumn(), true);
- context = new IHTMLReportContext() {
-
- public ILanguageNames getLanguageNames() {
- return new JavaNames();
- }
-
- public Resources getResources() {
- return resources;
- }
-
- public Table getTable() {
- return table;
- }
-
- public String getFooterText() {
- return "CustomFooter";
- }
-
- public ILinkable getSessionsPage() {
- return new LinkableStub("sessions.html", "Sessions",
- Styles.EL_SESSION);
- }
-
- public String getOutputEncoding() {
- return "UTF-8";
- }
-
- public IIndexUpdate getIndexUpdate() {
- return new IIndexUpdate() {
- public void addClass(ILinkable link, long classid) {
- }
- };
- }
-
- public Locale getLocale() {
- return Locale.ENGLISH;
- }
-
- };
- support = new HTMLSupport();
- }
-
- @After
- public void teardown() throws IOException {
- output.close();
- output.assertAllClosed();
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 java.io.IOException; +import java.util.Locale; + +import org.jacoco.report.ILanguageNames; +import org.jacoco.report.JavaNames; +import org.jacoco.report.MemoryMultiReportOutput; +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; +import org.jacoco.report.internal.html.table.LabelColumn; +import org.jacoco.report.internal.html.table.Table; +import org.junit.After; + +/** + * Unit tests for {@link ReportPage}. + */ +public abstract class PageTestBase { + + protected MemoryMultiReportOutput output; + + protected ReportOutputFolder rootFolder; + + protected IHTMLReportContext context; + + protected HTMLSupport support; + + protected void setup() throws Exception { + output = new MemoryMultiReportOutput(); + rootFolder = new ReportOutputFolder(output); + final Resources resources = new Resources(rootFolder); + final Table table = new Table(); + table.add("Element", null, new LabelColumn(), true); + context = new IHTMLReportContext() { + + public ILanguageNames getLanguageNames() { + return new JavaNames(); + } + + public Resources getResources() { + return resources; + } + + public Table getTable() { + return table; + } + + public String getFooterText() { + return "CustomFooter"; + } + + public ILinkable getSessionsPage() { + return new LinkableStub("sessions.html", "Sessions", + Styles.EL_SESSION); + } + + public String getOutputEncoding() { + return "UTF-8"; + } + + public IIndexUpdate getIndexUpdate() { + return new IIndexUpdate() { + public void addClass(ILinkable link, long classid) { + } + }; + } + + public Locale getLocale() { + return Locale.ENGLISH; + } + + }; + support = new HTMLSupport(); + } + + @After + public void teardown() throws IOException { + output.close(); + output.assertAllClosed(); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java index 27f5f8f3..ac26218f 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ReportPageTest.java @@ -1,128 +1,128 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-
-import org.jacoco.report.internal.ReportOutputFolder;
-import org.jacoco.report.internal.html.HTMLElement;
-import org.jacoco.report.internal.html.HTMLSupport;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link ReportPage}.
- */
-public class ReportPageTest extends PageTestBase {
-
- private ReportPage rootpage;
-
- private ReportPage page;
-
- private class TestReportPage extends ReportPage {
-
- private final String label;
- private final String style;
-
- protected TestReportPage(String label, String style, ReportPage parent) {
- super(parent, rootFolder, ReportPageTest.this.context);
- this.label = label;
- this.style = style;
- }
-
- @Override
- protected void content(HTMLElement body) throws IOException {
- body.div("testcontent").text("Hello Test");
- }
-
- @Override
- protected String getFileName() {
- return label + ".html";
- }
-
- public String getLinkLabel() {
- return label;
- }
-
- public String getLinkStyle() {
- return style;
- }
-
- }
-
- @Before
- @Override
- public void setup() throws Exception {
- super.setup();
- rootpage = new TestReportPage("Report", "el_report", null);
- page = new TestReportPage("Test", "el_group", rootpage);
- }
-
- @Test
- public void testIsRootPage1() {
- assertFalse(page.isRootPage());
- }
-
- @Test
- public void testIsRootPage2() {
- assertTrue(rootpage.isRootPage());
- }
-
- @Test
- public void testGetLink() throws IOException {
- ReportOutputFolder base = rootFolder.subFolder("here");
- assertEquals("../Test.html", page.getLink(base));
- }
-
- @Test
- public void testPageContent() throws Exception {
- page.render();
- final HTMLSupport support = new HTMLSupport();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- // language
- assertEquals("en", support.findStr(doc, "/html/@lang"));
-
- // style sheet
- assertEquals(".resources/report.css", support.findStr(doc,
- "/html/head/link[@rel='stylesheet']/@href"));
-
- // bread crumb
- assertEquals("Report", support.findStr(doc,
- "/html/body/div[@class='breadcrumb']/a[1]/text()"));
- assertEquals("Report.html", support.findStr(doc,
- "/html/body/div[@class='breadcrumb']/a[1]/@href"));
- assertEquals("el_report", support.findStr(doc,
- "/html/body/div[@class='breadcrumb']/a[1]/@class"));
- assertEquals("Test", support.findStr(doc,
- "/html/body/div[@class='breadcrumb']/span[2]/text()"));
- assertEquals("el_group", support.findStr(doc,
- "/html/body/div[@class='breadcrumb']/span[2]/@class"));
-
- // Header
- assertEquals("Test", support.findStr(doc, "/html/body/h1/text()"));
-
- // Content
- assertEquals("Hello Test", support.findStr(doc,
- "/html/body/div[@class='testcontent']/text()"));
-
- // Footer
- assertEquals("CustomFooter",
- support.findStr(doc, "/html/body/div[@class='footer']/text()"));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.jacoco.report.internal.ReportOutputFolder; +import org.jacoco.report.internal.html.HTMLElement; +import org.jacoco.report.internal.html.HTMLSupport; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link ReportPage}. + */ +public class ReportPageTest extends PageTestBase { + + private ReportPage rootpage; + + private ReportPage page; + + private class TestReportPage extends ReportPage { + + private final String label; + private final String style; + + protected TestReportPage(String label, String style, ReportPage parent) { + super(parent, rootFolder, ReportPageTest.this.context); + this.label = label; + this.style = style; + } + + @Override + protected void content(HTMLElement body) throws IOException { + body.div("testcontent").text("Hello Test"); + } + + @Override + protected String getFileName() { + return label + ".html"; + } + + public String getLinkLabel() { + return label; + } + + public String getLinkStyle() { + return style; + } + + } + + @Before + @Override + public void setup() throws Exception { + super.setup(); + rootpage = new TestReportPage("Report", "el_report", null); + page = new TestReportPage("Test", "el_group", rootpage); + } + + @Test + public void testIsRootPage1() { + assertFalse(page.isRootPage()); + } + + @Test + public void testIsRootPage2() { + assertTrue(rootpage.isRootPage()); + } + + @Test + public void testGetLink() throws IOException { + ReportOutputFolder base = rootFolder.subFolder("here"); + assertEquals("../Test.html", page.getLink(base)); + } + + @Test + public void testPageContent() throws Exception { + page.render(); + final HTMLSupport support = new HTMLSupport(); + final Document doc = support.parse(output.getFile("Test.html")); + + // language + assertEquals("en", support.findStr(doc, "/html/@lang")); + + // style sheet + assertEquals(".resources/report.css", support.findStr(doc, + "/html/head/link[@rel='stylesheet']/@href")); + + // bread crumb + assertEquals("Report", support.findStr(doc, + "/html/body/div[@class='breadcrumb']/a[1]/text()")); + assertEquals("Report.html", support.findStr(doc, + "/html/body/div[@class='breadcrumb']/a[1]/@href")); + assertEquals("el_report", support.findStr(doc, + "/html/body/div[@class='breadcrumb']/a[1]/@class")); + assertEquals("Test", support.findStr(doc, + "/html/body/div[@class='breadcrumb']/span[2]/text()")); + assertEquals("el_group", support.findStr(doc, + "/html/body/div[@class='breadcrumb']/span[2]/@class")); + + // Header + assertEquals("Test", support.findStr(doc, "/html/body/h1/text()")); + + // Content + assertEquals("Hello Test", support.findStr(doc, + "/html/body/div[@class='testcontent']/text()")); + + // Footer + assertEquals("CustomFooter", + support.findStr(doc, "/html/body/div[@class='footer']/text()")); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java index 7e9752ff..0eeb3c05 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/SourceHighlighterTest.java @@ -1,153 +1,153 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.StringReader;
-import java.io.StringWriter;
-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;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link SourceHighlighter}.
- */
-public class SourceHighlighterTest {
-
- private HTMLSupport htmlSupport;
-
- private StringWriter buffer;
-
- private HTMLDocument html;
-
- private HTMLElement parent;
-
- private SourceHighlighter sourceHighlighter;
-
- private SourceNodeImpl source;
-
- @Before
- public void setup() throws Exception {
- htmlSupport = new HTMLSupport();
- source = new SourceNodeImpl(ElementType.SOURCEFILE, "Foo.java");
- buffer = new StringWriter();
- html = new HTMLDocument(buffer, "UTF-8");
- html.head().title();
- parent = html.body();
- sourceHighlighter = new SourceHighlighter(Locale.US);
- }
-
- @Test
- public void testDefaultTabWidth() throws Exception {
- final String src = "\tA";
- sourceHighlighter.render(parent, source, new StringReader(src));
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
-
- // Assert that we no longer replace tabs with spaces
- assertEquals("\tA\n", htmlSupport.findStr(doc, "//pre/text()"));
- }
-
- @Test
- public void testDefaultLanguage() throws Exception {
- sourceHighlighter.render(parent, source, new StringReader(""));
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals("source lang-java linenums",
- htmlSupport.findStr(doc, "//pre/@class"));
- }
-
- @Test
- public void testSetLanguage() throws Exception {
- sourceHighlighter.setLanguage("scala");
- sourceHighlighter.render(parent, source, new StringReader(""));
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals("source lang-scala linenums",
- htmlSupport.findStr(doc, "//pre/@class"));
- }
-
- @Test
- public void testHighlighting() throws Exception {
- final String src = "A\nB\nC\nD";
- source.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
- source.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 2);
- source.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 2);
- source.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 3);
- sourceHighlighter.render(parent, source, new StringReader(src));
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals(Styles.NOT_COVERED,
- htmlSupport.findStr(doc, "//pre/span[text() = 'A']/@class"));
- assertEquals(Styles.PARTLY_COVERED,
- htmlSupport.findStr(doc, "//pre/span[text() = 'B']/@class"));
- assertEquals(Styles.FULLY_COVERED,
- htmlSupport.findStr(doc, "//pre/span[text() = 'C']/@class"));
- assertEquals("",
- htmlSupport.findStr(doc, "//pre/span[text() = 'D']/@class"));
- }
-
- @Test
- public void testHighlightNone() throws Exception {
- sourceHighlighter.highlight(parent, source.getLine(1), 1);
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals("", htmlSupport.findStr(doc, "//pre"));
- }
-
- @Test
- public void testHighlightBranchesFC() throws Exception {
- source.increment(CounterImpl.COUNTER_0_1,
- CounterImpl.getInstance(0, 5), 1);
- sourceHighlighter.highlight(parent.pre(null), source.getLine(1), 1);
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals("fc bfc", htmlSupport.findStr(doc, "//pre/span/@class"));
- assertEquals("All 5 branches covered.",
- htmlSupport.findStr(doc, "//pre/span/@title"));
- }
-
- @Test
- public void testHighlightBranchesPC() throws Exception {
- source.increment(CounterImpl.COUNTER_0_1,
- CounterImpl.getInstance(2, 3), 1);
- sourceHighlighter.highlight(parent.pre(null), source.getLine(1), 1);
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals("pc bpc", htmlSupport.findStr(doc, "//pre/span/@class"));
- assertEquals("2 of 5 branches missed.",
- htmlSupport.findStr(doc, "//pre/span/@title"));
- }
-
- @Test
- public void testHighlightBranchesNC() throws Exception {
- source.increment(CounterImpl.COUNTER_0_1,
- CounterImpl.getInstance(5, 0), 1);
- sourceHighlighter.highlight(parent.pre(null), source.getLine(1), 1);
- html.close();
- final Document doc = htmlSupport.parse(buffer.toString());
- assertEquals("pc bnc", htmlSupport.findStr(doc, "//pre/span/@class"));
- assertEquals("All 5 branches missed.",
- htmlSupport.findStr(doc, "//pre/span/@title"));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.StringReader; +import java.io.StringWriter; +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; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link SourceHighlighter}. + */ +public class SourceHighlighterTest { + + private HTMLSupport htmlSupport; + + private StringWriter buffer; + + private HTMLDocument html; + + private HTMLElement parent; + + private SourceHighlighter sourceHighlighter; + + private SourceNodeImpl source; + + @Before + public void setup() throws Exception { + htmlSupport = new HTMLSupport(); + source = new SourceNodeImpl(ElementType.SOURCEFILE, "Foo.java"); + buffer = new StringWriter(); + html = new HTMLDocument(buffer, "UTF-8"); + html.head().title(); + parent = html.body(); + sourceHighlighter = new SourceHighlighter(Locale.US); + } + + @Test + public void testDefaultTabWidth() throws Exception { + final String src = "\tA"; + sourceHighlighter.render(parent, source, new StringReader(src)); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + + // Assert that we no longer replace tabs with spaces + assertEquals("\tA\n", htmlSupport.findStr(doc, "//pre/text()")); + } + + @Test + public void testDefaultLanguage() throws Exception { + sourceHighlighter.render(parent, source, new StringReader("")); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals("source lang-java linenums", + htmlSupport.findStr(doc, "//pre/@class")); + } + + @Test + public void testSetLanguage() throws Exception { + sourceHighlighter.setLanguage("scala"); + sourceHighlighter.render(parent, source, new StringReader("")); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals("source lang-scala linenums", + htmlSupport.findStr(doc, "//pre/@class")); + } + + @Test + public void testHighlighting() throws Exception { + final String src = "A\nB\nC\nD"; + source.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1); + source.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 2); + source.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 2); + source.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 3); + sourceHighlighter.render(parent, source, new StringReader(src)); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals(Styles.NOT_COVERED, + htmlSupport.findStr(doc, "//pre/span[text() = 'A']/@class")); + assertEquals(Styles.PARTLY_COVERED, + htmlSupport.findStr(doc, "//pre/span[text() = 'B']/@class")); + assertEquals(Styles.FULLY_COVERED, + htmlSupport.findStr(doc, "//pre/span[text() = 'C']/@class")); + assertEquals("", + htmlSupport.findStr(doc, "//pre/span[text() = 'D']/@class")); + } + + @Test + public void testHighlightNone() throws Exception { + sourceHighlighter.highlight(parent, source.getLine(1), 1); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals("", htmlSupport.findStr(doc, "//pre")); + } + + @Test + public void testHighlightBranchesFC() throws Exception { + source.increment(CounterImpl.COUNTER_0_1, + CounterImpl.getInstance(0, 5), 1); + sourceHighlighter.highlight(parent.pre(null), source.getLine(1), 1); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals("fc bfc", htmlSupport.findStr(doc, "//pre/span/@class")); + assertEquals("All 5 branches covered.", + htmlSupport.findStr(doc, "//pre/span/@title")); + } + + @Test + public void testHighlightBranchesPC() throws Exception { + source.increment(CounterImpl.COUNTER_0_1, + CounterImpl.getInstance(2, 3), 1); + sourceHighlighter.highlight(parent.pre(null), source.getLine(1), 1); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals("pc bpc", htmlSupport.findStr(doc, "//pre/span/@class")); + assertEquals("2 of 5 branches missed.", + htmlSupport.findStr(doc, "//pre/span/@title")); + } + + @Test + public void testHighlightBranchesNC() throws Exception { + source.increment(CounterImpl.COUNTER_0_1, + CounterImpl.getInstance(5, 0), 1); + sourceHighlighter.highlight(parent.pre(null), source.getLine(1), 1); + html.close(); + final Document doc = htmlSupport.parse(buffer.toString()); + assertEquals("pc bnc", htmlSupport.findStr(doc, "//pre/span/@class")); + assertEquals("All 5 branches missed.", + htmlSupport.findStr(doc, "//pre/span/@title")); + } + +} 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 8548fe27..a3d0c6b9 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 @@ -1,86 +1,86 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.resources;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-
-import org.jacoco.core.analysis.ICoverageNode.ElementType;
-import org.jacoco.report.MemoryMultiReportOutput;
-import org.jacoco.report.internal.ReportOutputFolder;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link Resources}.
- */
-public class ResourcesTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private Resources resources;
-
- @Before
- public void setup() {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- resources = new Resources(root);
- }
-
- @Test
- public void testGetLink() {
- ReportOutputFolder base = root.subFolder("f1").subFolder("f2");
- assertEquals("../../.resources/test.png",
- resources.getLink(base, "test.png"));
-
- }
-
- @Test
- public void testCopyResources() throws IOException {
- resources.copyResources();
- output.assertFile(".resources/branchfc.gif");
- output.assertFile(".resources/branchnc.gif");
- output.assertFile(".resources/branchpc.gif");
- output.assertFile(".resources/bundle.gif");
- output.assertFile(".resources/class.gif");
- output.assertFile(".resources/down.gif");
- output.assertFile(".resources/greenbar.gif");
- output.assertFile(".resources/group.gif");
- output.assertFile(".resources/method.gif");
- output.assertFile(".resources/package.gif");
- output.assertFile(".resources/prettify.css");
- output.assertFile(".resources/prettify.js");
- output.assertFile(".resources/redbar.gif");
- output.assertFile(".resources/report.css");
- output.assertFile(".resources/report.gif");
- output.assertFile(".resources/class.gif");
- output.assertFile(".resources/sort.js");
- output.assertFile(".resources/source.gif");
- output.assertFile(".resources/up.gif");
- }
-
- @Test
- public void testGetElementStyle() {
- assertEquals("el_group", Resources.getElementStyle(ElementType.GROUP));
- assertEquals("el_bundle", Resources.getElementStyle(ElementType.BUNDLE));
- assertEquals("el_package",
- Resources.getElementStyle(ElementType.PACKAGE));
- assertEquals("el_source",
- Resources.getElementStyle(ElementType.SOURCEFILE));
- assertEquals("el_class", Resources.getElementStyle(ElementType.CLASS));
- assertEquals("el_method", Resources.getElementStyle(ElementType.METHOD));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.resources; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.jacoco.core.analysis.ICoverageNode.ElementType; +import org.jacoco.report.MemoryMultiReportOutput; +import org.jacoco.report.internal.ReportOutputFolder; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link Resources}. + */ +public class ResourcesTest { + + private MemoryMultiReportOutput output; + + private ReportOutputFolder root; + + private Resources resources; + + @Before + public void setup() { + output = new MemoryMultiReportOutput(); + root = new ReportOutputFolder(output); + resources = new Resources(root); + } + + @Test + public void testGetLink() { + ReportOutputFolder base = root.subFolder("f1").subFolder("f2"); + assertEquals("../../.resources/test.png", + resources.getLink(base, "test.png")); + + } + + @Test + public void testCopyResources() throws IOException { + resources.copyResources(); + output.assertFile(".resources/branchfc.gif"); + output.assertFile(".resources/branchnc.gif"); + output.assertFile(".resources/branchpc.gif"); + output.assertFile(".resources/bundle.gif"); + output.assertFile(".resources/class.gif"); + output.assertFile(".resources/down.gif"); + output.assertFile(".resources/greenbar.gif"); + output.assertFile(".resources/group.gif"); + output.assertFile(".resources/method.gif"); + output.assertFile(".resources/package.gif"); + output.assertFile(".resources/prettify.css"); + output.assertFile(".resources/prettify.js"); + output.assertFile(".resources/redbar.gif"); + output.assertFile(".resources/report.css"); + output.assertFile(".resources/report.gif"); + output.assertFile(".resources/class.gif"); + output.assertFile(".resources/sort.js"); + output.assertFile(".resources/source.gif"); + output.assertFile(".resources/up.gif"); + } + + @Test + public void testGetElementStyle() { + assertEquals("el_group", Resources.getElementStyle(ElementType.GROUP)); + assertEquals("el_bundle", Resources.getElementStyle(ElementType.BUNDLE)); + assertEquals("el_package", + Resources.getElementStyle(ElementType.PACKAGE)); + assertEquals("el_source", + Resources.getElementStyle(ElementType.SOURCEFILE)); + assertEquals("el_class", Resources.getElementStyle(ElementType.CLASS)); + assertEquals("el_method", Resources.getElementStyle(ElementType.METHOD)); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/StylesTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/StylesTest.java index 50c93fe3..f783728c 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/StylesTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/resources/StylesTest.java @@ -1,44 +1,44 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.resources;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-/**
- * Unit tests for {@link Styles}.
- */
-public class StylesTest {
-
- @Test
- public void testCombine1() {
- assertEquals(null, Styles.combine());
- }
-
- @Test
- public void testCombine2() {
- assertEquals(null, Styles.combine((String) null));
- }
-
- @Test
- public void testCombine3() {
- assertEquals("aaa", Styles.combine("aaa"));
- }
-
- @Test
- public void testCombine4() {
- assertEquals("aaa bbb ccc",
- Styles.combine("aaa", null, "bbb", "ccc", null));
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.resources; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Unit tests for {@link Styles}. + */ +public class StylesTest { + + @Test + public void testCombine1() { + assertEquals(null, Styles.combine()); + } + + @Test + public void testCombine2() { + assertEquals(null, Styles.combine((String) null)); + } + + @Test + public void testCombine3() { + assertEquals("aaa", Styles.combine("aaa")); + } + + @Test + public void testCombine4() { + assertEquals("aaa bbb ccc", + Styles.combine("aaa", null, "bbb", "ccc", null)); + } + +} 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 115d3623..ba5e33dd 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 @@ -1,236 +1,236 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.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;
-
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.ICoverageNode;
-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.internal.ReportOutputFolder;
-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.Resources;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link BarColumn}.
- */
-public class BarColumnTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private Resources resources;
-
- private HTMLDocument doc;
-
- private HTMLElement td;
-
- private HTMLSupport support;
-
- private IColumnRenderer column;
-
- @Before
- public void setup() throws Exception {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- resources = new Resources(root);
- doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
- doc.head().title();
- td = doc.body().table("somestyle").tr().td();
- support = new HTMLSupport();
- column = new BarColumn(CounterEntity.LINE, Locale.ENGLISH);
- }
-
- @After
- public void teardown() throws IOException {
- output.close();
- output.assertAllClosed();
- }
-
- @Test
- public void testInit() throws Exception {
- final ITableItem i = createItem(6, 24);
- assertTrue(column.init(Arrays.asList(i), i.getNode()));
- doc.close();
- }
-
- @Test
- public void testFooter() throws Exception {
- column.footer(td, createNode(15, 5), resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("15 of 20",
- support.findStr(doc, "/html/body/table/tr/td/text()"));
- }
-
- @Test
- public void testBarWidths() throws Exception {
- final ITableItem i1 = createItem(15, 5);
- final ITableItem i2 = createItem(6, 24);
- column.init(Arrays.asList(i1, i2), createNode(21, 29));
- column.item(td, i1, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- assertEquals("2",
- support.findStr(doc, "count(/html/body/table/tr[1]/td/img)"));
-
- // red bar
- assertEquals(".resources/redbar.gif",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@src"));
- assertEquals("15",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt"));
- assertEquals("60",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@width"));
-
- // green bar
- assertEquals(".resources/greenbar.gif",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[2]/@src"));
- assertEquals("5",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[2]/@alt"));
- assertEquals("20",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[2]/@width"));
- }
-
- @Test
- public void testRedBarOnly() throws Exception {
- final ITableItem i1 = createItem(20, 0);
- column.init(Arrays.asList(i1), createNode(20, 0));
- column.item(td, i1, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- assertEquals("1",
- support.findStr(doc, "count(/html/body/table/tr[1]/td/img)"));
-
- // red bar
- assertEquals(".resources/redbar.gif",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@src"));
- assertEquals("20",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt"));
- assertEquals("120",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@width"));
- }
-
- @Test
- public void testGreenBarOnly() throws Exception {
- final ITableItem i1 = createItem(00, 20);
- column.init(Arrays.asList(i1), createNode(00, 20));
- column.item(td, i1, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- assertEquals("1",
- support.findStr(doc, "count(/html/body/table/tr[1]/td/img)"));
-
- // red bar
- assertEquals(".resources/greenbar.gif",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@src"));
- assertEquals("20",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt"));
- assertEquals("120",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@width"));
- }
-
- @Test
- public void testNoBars() throws Exception {
- final ITableItem i1 = createItem(00, 00);
- column.init(Arrays.asList(i1), createNode(00, 00));
- column.item(td, i1, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- assertEquals("0",
- support.findStr(doc, "count(/html/body/table/tr[1]/td/img)"));
- }
-
- @Test
- public void testLocale() throws Exception {
- final BarColumn col = new BarColumn(CounterEntity.LINE, Locale.FRENCH);
- final ITableItem i1 = createItem(0, 123456);
- col.init(Arrays.asList(i1), createNode(00, 20));
- col.item(td, i1, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- assertEquals("123\u00a0456",
- support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt"));
- }
-
- @Test
- public void testComparator1() throws Exception {
- final Comparator<ITableItem> c = column.getComparator();
- final ITableItem i1 = createItem(50, 50);
- final ITableItem i2 = createItem(20, 80);
- assertTrue(c.compare(i1, i2) < 0);
- assertTrue(c.compare(i2, i1) > 0);
- assertEquals(0, c.compare(i1, i1));
- doc.close();
- }
-
- @Test
- public void testComparator2() throws Exception {
- final Comparator<ITableItem> c = column.getComparator();
- final ITableItem i1 = createItem(50, 60);
- final ITableItem i2 = createItem(50, 50);
- assertTrue(c.compare(i1, i2) < 0);
- assertTrue(c.compare(i2, i1) > 0);
- assertEquals(0, c.compare(i1, i1));
- doc.close();
- }
-
- private ITableItem createItem(final int missed, final int covered) {
- final ICoverageNode node = createNode(missed, covered);
- return new ITableItem() {
- public String getLinkLabel() {
- return "Foo";
- }
-
- public String getLink(ReportOutputFolder base) {
- return null;
- }
-
- public String getLinkStyle() {
- return Resources.getElementStyle(node.getElementType());
- }
-
- public ICoverageNode getNode() {
- return node;
- }
- };
- }
-
- private CoverageNodeImpl createNode(final int missed, final int covered) {
- return new CoverageNodeImpl(ElementType.GROUP, "Foo") {
- {
- this.lineCounter = CounterImpl.getInstance(missed, covered);
- }
- };
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.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; + +import org.jacoco.core.analysis.CoverageNodeImpl; +import org.jacoco.core.analysis.ICoverageNode; +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.internal.ReportOutputFolder; +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.Resources; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link BarColumn}. + */ +public class BarColumnTest { + + private MemoryMultiReportOutput output; + + private ReportOutputFolder root; + + private Resources resources; + + private HTMLDocument doc; + + private HTMLElement td; + + private HTMLSupport support; + + private IColumnRenderer column; + + @Before + public void setup() throws Exception { + output = new MemoryMultiReportOutput(); + root = new ReportOutputFolder(output); + resources = new Resources(root); + doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8"); + doc.head().title(); + td = doc.body().table("somestyle").tr().td(); + support = new HTMLSupport(); + column = new BarColumn(CounterEntity.LINE, Locale.ENGLISH); + } + + @After + public void teardown() throws IOException { + output.close(); + output.assertAllClosed(); + } + + @Test + public void testInit() throws Exception { + final ITableItem i = createItem(6, 24); + assertTrue(column.init(Arrays.asList(i), i.getNode())); + doc.close(); + } + + @Test + public void testFooter() throws Exception { + column.footer(td, createNode(15, 5), resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("15 of 20", + support.findStr(doc, "/html/body/table/tr/td/text()")); + } + + @Test + public void testBarWidths() throws Exception { + final ITableItem i1 = createItem(15, 5); + final ITableItem i2 = createItem(6, 24); + column.init(Arrays.asList(i1, i2), createNode(21, 29)); + column.item(td, i1, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + + assertEquals("2", + support.findStr(doc, "count(/html/body/table/tr[1]/td/img)")); + + // red bar + assertEquals(".resources/redbar.gif", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@src")); + assertEquals("15", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt")); + assertEquals("60", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@width")); + + // green bar + assertEquals(".resources/greenbar.gif", + support.findStr(doc, "/html/body/table/tr[1]/td/img[2]/@src")); + assertEquals("5", + support.findStr(doc, "/html/body/table/tr[1]/td/img[2]/@alt")); + assertEquals("20", + support.findStr(doc, "/html/body/table/tr[1]/td/img[2]/@width")); + } + + @Test + public void testRedBarOnly() throws Exception { + final ITableItem i1 = createItem(20, 0); + column.init(Arrays.asList(i1), createNode(20, 0)); + column.item(td, i1, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + + assertEquals("1", + support.findStr(doc, "count(/html/body/table/tr[1]/td/img)")); + + // red bar + assertEquals(".resources/redbar.gif", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@src")); + assertEquals("20", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt")); + assertEquals("120", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@width")); + } + + @Test + public void testGreenBarOnly() throws Exception { + final ITableItem i1 = createItem(00, 20); + column.init(Arrays.asList(i1), createNode(00, 20)); + column.item(td, i1, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + + assertEquals("1", + support.findStr(doc, "count(/html/body/table/tr[1]/td/img)")); + + // red bar + assertEquals(".resources/greenbar.gif", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@src")); + assertEquals("20", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt")); + assertEquals("120", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@width")); + } + + @Test + public void testNoBars() throws Exception { + final ITableItem i1 = createItem(00, 00); + column.init(Arrays.asList(i1), createNode(00, 00)); + column.item(td, i1, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + + assertEquals("0", + support.findStr(doc, "count(/html/body/table/tr[1]/td/img)")); + } + + @Test + public void testLocale() throws Exception { + final BarColumn col = new BarColumn(CounterEntity.LINE, Locale.FRENCH); + final ITableItem i1 = createItem(0, 123456); + col.init(Arrays.asList(i1), createNode(00, 20)); + col.item(td, i1, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + + assertEquals("123\u00a0456", + support.findStr(doc, "/html/body/table/tr[1]/td/img[1]/@alt")); + } + + @Test + public void testComparator1() throws Exception { + final Comparator<ITableItem> c = column.getComparator(); + final ITableItem i1 = createItem(50, 50); + final ITableItem i2 = createItem(20, 80); + assertTrue(c.compare(i1, i2) < 0); + assertTrue(c.compare(i2, i1) > 0); + assertEquals(0, c.compare(i1, i1)); + doc.close(); + } + + @Test + public void testComparator2() throws Exception { + final Comparator<ITableItem> c = column.getComparator(); + final ITableItem i1 = createItem(50, 60); + final ITableItem i2 = createItem(50, 50); + assertTrue(c.compare(i1, i2) < 0); + assertTrue(c.compare(i2, i1) > 0); + assertEquals(0, c.compare(i1, i1)); + doc.close(); + } + + private ITableItem createItem(final int missed, final int covered) { + final ICoverageNode node = createNode(missed, covered); + return new ITableItem() { + public String getLinkLabel() { + return "Foo"; + } + + public String getLink(ReportOutputFolder base) { + return null; + } + + public String getLinkStyle() { + return Resources.getElementStyle(node.getElementType()); + } + + public ICoverageNode getNode() { + return node; + } + }; + } + + private CoverageNodeImpl createNode(final int missed, final int covered) { + return new CoverageNodeImpl(ElementType.GROUP, "Foo") { + { + this.lineCounter = CounterImpl.getInstance(missed, covered); + } + }; + } + +} 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 6a84a4e0..6d877fe6 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 @@ -1,227 +1,227 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.table;
-
-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;
-import java.util.Locale;
-
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.ICoverageNode;
-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.internal.ReportOutputFolder;
-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.Resources;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link CounterColumn}.
- */
-public class CounterColumnTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private Resources resources;
-
- private HTMLDocument doc;
-
- private HTMLElement td;
-
- private HTMLSupport support;
-
- private Locale locale;
-
- @Before
- public void setup() throws Exception {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- resources = new Resources(root);
- doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
- doc.head().title();
- td = doc.body().table("somestyle").tr().td();
- support = new HTMLSupport();
- locale = Locale.ENGLISH;
- }
-
- @After
- public void teardown() throws IOException {
- output.close();
- output.assertAllClosed();
- }
-
- @Test
- public void testInitVisible() throws Exception {
- IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE,
- locale);
- final ITableItem item = createItem(0, 3);
- assertTrue(column.init(Arrays.asList(item), item.getNode()));
- doc.close();
- }
-
- @Test
- public void testInitInvisible() throws Exception {
- IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE,
- locale);
- final ITableItem item = createItem(0, 0);
- assertFalse(column.init(Arrays.asList(item), createNode(1, 0)));
- doc.close();
- }
-
- @Test
- public void testItemTotal() throws Exception {
- IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE,
- locale);
- final ITableItem item = createItem(100, 50);
- column.init(Collections.singletonList(item), item.getNode());
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("150",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testItemMissed() throws Exception {
- IColumnRenderer column = CounterColumn.newMissed(CounterEntity.LINE,
- locale);
- final ITableItem item = createItem(100, 50);
- column.init(Collections.singletonList(item), item.getNode());
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("100",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testItemCovered() throws Exception {
- IColumnRenderer column = CounterColumn.newCovered(CounterEntity.LINE,
- locale);
- final ITableItem item = createItem(100, 50);
- column.init(Collections.singletonList(item), item.getNode());
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("50",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testLocale() throws Exception {
- IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE,
- Locale.ITALIAN);
- final ITableItem item = createItem(1000, 0);
- column.init(Collections.singletonList(item), item.getNode());
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("1.000",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testFooter() throws Exception {
- IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE,
- locale);
- final ITableItem item = createItem(20, 60);
- column.init(Collections.singletonList(item), item.getNode());
- column.footer(td, item.getNode(), resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("80",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testComparatorTotal() throws Exception {
- IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE,
- locale);
- final Comparator<ITableItem> c = column.getComparator();
- final ITableItem i1 = createItem(30, 0);
- final ITableItem i2 = createItem(40, 0);
- assertEquals(0, c.compare(i1, i1));
- assertTrue(c.compare(i1, i2) > 0);
- assertTrue(c.compare(i2, i1) < 0);
- doc.close();
- }
-
- @Test
- public void testComparatorCovered() throws Exception {
- IColumnRenderer column = CounterColumn.newCovered(CounterEntity.LINE,
- locale);
- final Comparator<ITableItem> c = column.getComparator();
- final ITableItem i1 = createItem(70, 30);
- final ITableItem i2 = createItem(50, 50);
- assertEquals(0, c.compare(i1, i1));
- assertTrue(c.compare(i1, i2) > 0);
- assertTrue(c.compare(i2, i1) < 0);
- doc.close();
- }
-
- @Test
- public void testComparatorMissed() throws Exception {
- IColumnRenderer column = CounterColumn.newMissed(CounterEntity.LINE,
- locale);
- final Comparator<ITableItem> c = column.getComparator();
- final ITableItem i1 = createItem(20, 80);
- final ITableItem i2 = createItem(50, 50);
- assertEquals(0, c.compare(i1, i1));
- assertTrue(c.compare(i1, i2) > 0);
- assertTrue(c.compare(i2, i1) < 0);
- doc.close();
- }
-
- private ITableItem createItem(final int missed, final int covered) {
- final ICoverageNode node = createNode(missed, covered);
- return new ITableItem() {
- public String getLinkLabel() {
- return "Foo";
- }
-
- public String getLink(ReportOutputFolder base) {
- return null;
- }
-
- public String getLinkStyle() {
- return Resources.getElementStyle(node.getElementType());
- }
-
- public ICoverageNode getNode() {
- return node;
- }
- };
- }
-
- private CoverageNodeImpl createNode(final int missed, final int covered) {
- return new CoverageNodeImpl(ElementType.GROUP, "Foo") {
- {
- this.lineCounter = CounterImpl.getInstance(missed, covered);
- }
- };
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.table; + +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; +import java.util.Locale; + +import org.jacoco.core.analysis.CoverageNodeImpl; +import org.jacoco.core.analysis.ICoverageNode; +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.internal.ReportOutputFolder; +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.Resources; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link CounterColumn}. + */ +public class CounterColumnTest { + + private MemoryMultiReportOutput output; + + private ReportOutputFolder root; + + private Resources resources; + + private HTMLDocument doc; + + private HTMLElement td; + + private HTMLSupport support; + + private Locale locale; + + @Before + public void setup() throws Exception { + output = new MemoryMultiReportOutput(); + root = new ReportOutputFolder(output); + resources = new Resources(root); + doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8"); + doc.head().title(); + td = doc.body().table("somestyle").tr().td(); + support = new HTMLSupport(); + locale = Locale.ENGLISH; + } + + @After + public void teardown() throws IOException { + output.close(); + output.assertAllClosed(); + } + + @Test + public void testInitVisible() throws Exception { + IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE, + locale); + final ITableItem item = createItem(0, 3); + assertTrue(column.init(Arrays.asList(item), item.getNode())); + doc.close(); + } + + @Test + public void testInitInvisible() throws Exception { + IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE, + locale); + final ITableItem item = createItem(0, 0); + assertFalse(column.init(Arrays.asList(item), createNode(1, 0))); + doc.close(); + } + + @Test + public void testItemTotal() throws Exception { + IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE, + locale); + final ITableItem item = createItem(100, 50); + column.init(Collections.singletonList(item), item.getNode()); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("150", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testItemMissed() throws Exception { + IColumnRenderer column = CounterColumn.newMissed(CounterEntity.LINE, + locale); + final ITableItem item = createItem(100, 50); + column.init(Collections.singletonList(item), item.getNode()); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("100", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testItemCovered() throws Exception { + IColumnRenderer column = CounterColumn.newCovered(CounterEntity.LINE, + locale); + final ITableItem item = createItem(100, 50); + column.init(Collections.singletonList(item), item.getNode()); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("50", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testLocale() throws Exception { + IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE, + Locale.ITALIAN); + final ITableItem item = createItem(1000, 0); + column.init(Collections.singletonList(item), item.getNode()); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("1.000", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testFooter() throws Exception { + IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE, + locale); + final ITableItem item = createItem(20, 60); + column.init(Collections.singletonList(item), item.getNode()); + column.footer(td, item.getNode(), resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("80", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testComparatorTotal() throws Exception { + IColumnRenderer column = CounterColumn.newTotal(CounterEntity.LINE, + locale); + final Comparator<ITableItem> c = column.getComparator(); + final ITableItem i1 = createItem(30, 0); + final ITableItem i2 = createItem(40, 0); + assertEquals(0, c.compare(i1, i1)); + assertTrue(c.compare(i1, i2) > 0); + assertTrue(c.compare(i2, i1) < 0); + doc.close(); + } + + @Test + public void testComparatorCovered() throws Exception { + IColumnRenderer column = CounterColumn.newCovered(CounterEntity.LINE, + locale); + final Comparator<ITableItem> c = column.getComparator(); + final ITableItem i1 = createItem(70, 30); + final ITableItem i2 = createItem(50, 50); + assertEquals(0, c.compare(i1, i1)); + assertTrue(c.compare(i1, i2) > 0); + assertTrue(c.compare(i2, i1) < 0); + doc.close(); + } + + @Test + public void testComparatorMissed() throws Exception { + IColumnRenderer column = CounterColumn.newMissed(CounterEntity.LINE, + locale); + final Comparator<ITableItem> c = column.getComparator(); + final ITableItem i1 = createItem(20, 80); + final ITableItem i2 = createItem(50, 50); + assertEquals(0, c.compare(i1, i1)); + assertTrue(c.compare(i1, i2) > 0); + assertTrue(c.compare(i2, i1) < 0); + doc.close(); + } + + private ITableItem createItem(final int missed, final int covered) { + final ICoverageNode node = createNode(missed, covered); + return new ITableItem() { + public String getLinkLabel() { + return "Foo"; + } + + public String getLink(ReportOutputFolder base) { + return null; + } + + public String getLinkStyle() { + return Resources.getElementStyle(node.getElementType()); + } + + public ICoverageNode getNode() { + return node; + } + }; + } + + private CoverageNodeImpl createNode(final int missed, final int covered) { + return new CoverageNodeImpl(ElementType.GROUP, "Foo") { + { + this.lineCounter = CounterImpl.getInstance(missed, covered); + } + }; + } +} 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 a5f05f48..0689a12c 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 @@ -1,148 +1,148 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.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.internal.ReportOutputFolder;
-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.Resources;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link LabelColumn}.
- */
-public class LabelColumnTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private Resources resources;
-
- private HTMLDocument doc;
-
- private HTMLElement td;
-
- private HTMLSupport support;
-
- private IColumnRenderer column;
-
- @Before
- public void setup() throws Exception {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- resources = new Resources(root);
- doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
- doc.head().title();
- td = doc.body().table("somestyle").tr().td();
- support = new HTMLSupport();
- column = new LabelColumn();
- }
-
- @After
- public void teardown() throws IOException {
- output.close();
- output.assertAllClosed();
- }
-
- @Test
- public void testInit() throws Exception {
- assertTrue(column.init(null, null));
- doc.close();
- }
-
- @Test
- public void testFooter() throws Exception {
- column.footer(td, new CoverageNodeImpl(ElementType.GROUP, "Foo"),
- resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("Total",
- support.findStr(doc, "/html/body/table/tr/td/text()"));
- }
-
- @Test
- public void testItemWithoutLink() throws Exception {
- column.item(td, createItem("Abc", null), resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("Abc",
- support.findStr(doc, "/html/body/table/tr/td/span/text()"));
- assertEquals("el_group",
- support.findStr(doc, "/html/body/table/tr/td/span/@class"));
- }
-
- @Test
- public void testItemWithLink() throws Exception {
- column.item(td, createItem("Def", "def.html"), resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("Def",
- support.findStr(doc, "/html/body/table/tr/td/a/text()"));
- assertEquals("def.html",
- support.findStr(doc, "/html/body/table/tr/td/a/@href"));
- assertEquals("el_group",
- support.findStr(doc, "/html/body/table/tr/td/a/@class"));
- }
-
- @Test
- public void testComparator1() throws Exception {
- final ITableItem i1 = createItem("abcdef", null);
- final ITableItem i2 = createItem("aBcDeF", null);
- assertEquals(0, column.getComparator().compare(i1, i2));
- doc.close();
- }
-
- @Test
- public void testComparator2() throws Exception {
- final ITableItem i1 = createItem("hello", null);
- final ITableItem i2 = createItem("world", null);
- assertTrue(column.getComparator().compare(i1, i2) < 0);
- assertTrue(column.getComparator().compare(i2, i1) > 0);
- doc.close();
- }
-
- private ITableItem createItem(final String name, final String link) {
- final ICoverageNode node = new CoverageNodeImpl(ElementType.GROUP, name);
- return new ITableItem() {
- public String getLinkLabel() {
- return name;
- }
-
- public String getLink(ReportOutputFolder base) {
- return link;
- }
-
- public String getLinkStyle() {
- return Resources.getElementStyle(node.getElementType());
- }
-
- public ICoverageNode getNode() {
- return node;
- }
- };
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.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.internal.ReportOutputFolder; +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.Resources; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link LabelColumn}. + */ +public class LabelColumnTest { + + private MemoryMultiReportOutput output; + + private ReportOutputFolder root; + + private Resources resources; + + private HTMLDocument doc; + + private HTMLElement td; + + private HTMLSupport support; + + private IColumnRenderer column; + + @Before + public void setup() throws Exception { + output = new MemoryMultiReportOutput(); + root = new ReportOutputFolder(output); + resources = new Resources(root); + doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8"); + doc.head().title(); + td = doc.body().table("somestyle").tr().td(); + support = new HTMLSupport(); + column = new LabelColumn(); + } + + @After + public void teardown() throws IOException { + output.close(); + output.assertAllClosed(); + } + + @Test + public void testInit() throws Exception { + assertTrue(column.init(null, null)); + doc.close(); + } + + @Test + public void testFooter() throws Exception { + column.footer(td, new CoverageNodeImpl(ElementType.GROUP, "Foo"), + resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("Total", + support.findStr(doc, "/html/body/table/tr/td/text()")); + } + + @Test + public void testItemWithoutLink() throws Exception { + column.item(td, createItem("Abc", null), resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("Abc", + support.findStr(doc, "/html/body/table/tr/td/span/text()")); + assertEquals("el_group", + support.findStr(doc, "/html/body/table/tr/td/span/@class")); + } + + @Test + public void testItemWithLink() throws Exception { + column.item(td, createItem("Def", "def.html"), resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("Def", + support.findStr(doc, "/html/body/table/tr/td/a/text()")); + assertEquals("def.html", + support.findStr(doc, "/html/body/table/tr/td/a/@href")); + assertEquals("el_group", + support.findStr(doc, "/html/body/table/tr/td/a/@class")); + } + + @Test + public void testComparator1() throws Exception { + final ITableItem i1 = createItem("abcdef", null); + final ITableItem i2 = createItem("aBcDeF", null); + assertEquals(0, column.getComparator().compare(i1, i2)); + doc.close(); + } + + @Test + public void testComparator2() throws Exception { + final ITableItem i1 = createItem("hello", null); + final ITableItem i2 = createItem("world", null); + assertTrue(column.getComparator().compare(i1, i2) < 0); + assertTrue(column.getComparator().compare(i2, i1) > 0); + doc.close(); + } + + private ITableItem createItem(final String name, final String link) { + final ICoverageNode node = new CoverageNodeImpl(ElementType.GROUP, name); + return new ITableItem() { + public String getLinkLabel() { + return name; + } + + public String getLink(ReportOutputFolder base) { + return link; + } + + public String getLinkStyle() { + return Resources.getElementStyle(node.getElementType()); + } + + public ICoverageNode getNode() { + return node; + } + }; + } + +} 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 70210655..3c47ab2d 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 @@ -1,169 +1,169 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.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;
-
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.ICoverageNode;
-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.internal.ReportOutputFolder;
-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.Resources;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link PercentageColumn}.
- */
-public class PercentageColumnTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private Resources resources;
-
- private HTMLDocument doc;
-
- private HTMLElement td;
-
- private HTMLSupport support;
-
- private IColumnRenderer column;
-
- @Before
- public void setup() throws Exception {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- resources = new Resources(root);
- doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
- doc.head().title();
- td = doc.body().table("somestyle").tr().td();
- support = new HTMLSupport();
- column = new PercentageColumn(CounterEntity.LINE, Locale.ENGLISH);
- }
-
- @After
- public void teardown() throws IOException {
- output.close();
- output.assertAllClosed();
- }
-
- @Test
- public void testInit() throws Exception {
- assertTrue(column.init(null, null));
- doc.close();
- }
-
- @Test
- public void testItem1() throws Exception {
- final ITableItem item = createItem(100, 50);
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("33%",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testItem2() throws Exception {
- final ITableItem item = createItem(0, 0);
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("n/a",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testLocale() throws Exception {
- IColumnRenderer column = new PercentageColumn(CounterEntity.LINE,
- Locale.FRENCH);
- final ITableItem item = createItem(0, 1000);
- column.item(td, item, resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("100 %",
- support.findStr(doc, "/html/body/table/tr/td[1]/text()"));
- }
-
- @Test
- public void testFooter1() throws Exception {
- final ITableItem item = createItem(20, 60);
- column.footer(td, item.getNode(), resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("75%", support.findStr(doc, "/html/body/table/tr"));
- }
-
- @Test
- public void testFooter2() throws Exception {
- final ITableItem item = createItem(0, 0);
- column.footer(td, item.getNode(), resources, root);
- doc.close();
- final Document doc = support.parse(output.getFile("Test.html"));
- assertEquals("n/a", support.findStr(doc, "/html/body/table/tr"));
- }
-
- @Test
- public void testComparator() throws Exception {
- final Comparator<ITableItem> c = column.getComparator();
- final ITableItem i1 = createItem(50, 50);
- final ITableItem i2 = createItem(800, 200);
- assertTrue(c.compare(i1, i2) < 0);
- assertTrue(c.compare(i2, i1) > 0);
- assertEquals(0, c.compare(i1, i1));
- doc.close();
- }
-
- private ITableItem createItem(final int missed, final int covered) {
- final ICoverageNode node = createNode(missed, covered);
- return new ITableItem() {
- public String getLinkLabel() {
- return "Foo";
- }
-
- public String getLink(ReportOutputFolder base) {
- return null;
- }
-
- public String getLinkStyle() {
- return Resources.getElementStyle(node.getElementType());
- }
-
- public ICoverageNode getNode() {
- return node;
- }
- };
- }
-
- private CoverageNodeImpl createNode(final int missed, final int covered) {
- return new CoverageNodeImpl(ElementType.GROUP, "Foo") {
- {
- this.lineCounter = CounterImpl.getInstance(missed, covered);
- }
- };
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.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; + +import org.jacoco.core.analysis.CoverageNodeImpl; +import org.jacoco.core.analysis.ICoverageNode; +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.internal.ReportOutputFolder; +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.Resources; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link PercentageColumn}. + */ +public class PercentageColumnTest { + + private MemoryMultiReportOutput output; + + private ReportOutputFolder root; + + private Resources resources; + + private HTMLDocument doc; + + private HTMLElement td; + + private HTMLSupport support; + + private IColumnRenderer column; + + @Before + public void setup() throws Exception { + output = new MemoryMultiReportOutput(); + root = new ReportOutputFolder(output); + resources = new Resources(root); + doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8"); + doc.head().title(); + td = doc.body().table("somestyle").tr().td(); + support = new HTMLSupport(); + column = new PercentageColumn(CounterEntity.LINE, Locale.ENGLISH); + } + + @After + public void teardown() throws IOException { + output.close(); + output.assertAllClosed(); + } + + @Test + public void testInit() throws Exception { + assertTrue(column.init(null, null)); + doc.close(); + } + + @Test + public void testItem1() throws Exception { + final ITableItem item = createItem(100, 50); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("33%", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testItem2() throws Exception { + final ITableItem item = createItem(0, 0); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("n/a", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testLocale() throws Exception { + IColumnRenderer column = new PercentageColumn(CounterEntity.LINE, + Locale.FRENCH); + final ITableItem item = createItem(0, 1000); + column.item(td, item, resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("100 %", + support.findStr(doc, "/html/body/table/tr/td[1]/text()")); + } + + @Test + public void testFooter1() throws Exception { + final ITableItem item = createItem(20, 60); + column.footer(td, item.getNode(), resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("75%", support.findStr(doc, "/html/body/table/tr")); + } + + @Test + public void testFooter2() throws Exception { + final ITableItem item = createItem(0, 0); + column.footer(td, item.getNode(), resources, root); + doc.close(); + final Document doc = support.parse(output.getFile("Test.html")); + assertEquals("n/a", support.findStr(doc, "/html/body/table/tr")); + } + + @Test + public void testComparator() throws Exception { + final Comparator<ITableItem> c = column.getComparator(); + final ITableItem i1 = createItem(50, 50); + final ITableItem i2 = createItem(800, 200); + assertTrue(c.compare(i1, i2) < 0); + assertTrue(c.compare(i2, i1) > 0); + assertEquals(0, c.compare(i1, i1)); + doc.close(); + } + + private ITableItem createItem(final int missed, final int covered) { + final ICoverageNode node = createNode(missed, covered); + return new ITableItem() { + public String getLinkLabel() { + return "Foo"; + } + + public String getLink(ReportOutputFolder base) { + return null; + } + + public String getLinkStyle() { + return Resources.getElementStyle(node.getElementType()); + } + + public ICoverageNode getNode() { + return node; + } + }; + } + + private CoverageNodeImpl createNode(final int missed, final int covered) { + return new CoverageNodeImpl(ElementType.GROUP, "Foo") { + { + this.lineCounter = CounterImpl.getInstance(missed, covered); + } + }; + } +} 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 3bd5d53c..dcc216c4 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 @@ -1,285 +1,285 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.table;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-import org.jacoco.core.analysis.CounterComparator;
-import org.jacoco.core.analysis.CoverageNodeImpl;
-import org.jacoco.core.analysis.ICoverageNode;
-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.internal.ReportOutputFolder;
-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.Resources;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Unit tests for {@link Table}.
- */
-public class TableTest {
-
- private MemoryMultiReportOutput output;
-
- private ReportOutputFolder root;
-
- private Resources resources;
-
- private HTMLDocument doc;
-
- private HTMLElement body;
-
- private Table table;
-
- @Before
- public void setup() throws IOException {
- output = new MemoryMultiReportOutput();
- root = new ReportOutputFolder(output);
- resources = new Resources(root);
- doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
- doc.head().title();
- body = doc.body();
- table = new Table();
- }
-
- @After
- public void teardown() throws IOException {
- output.close();
- output.assertAllClosed();
- }
-
- @Test
- public void testCallbackSequence() throws IOException {
- final IColumnRenderer recorder = new StubRenderer(
- CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)) {
-
- private final StringBuilder store = new StringBuilder();
-
- @Override
- public boolean init(List<? extends ITableItem> items,
- ICoverageNode total) {
- store.append("init-");
- return true;
- }
-
- @Override
- public void footer(HTMLElement td, ICoverageNode total,
- Resources resources, ReportOutputFolder base) {
- store.append("footer-");
- }
-
- @Override
- public void item(HTMLElement td, ITableItem item,
- Resources resources, ReportOutputFolder base) {
- store.append("item").append(item.getLinkLabel()).append("-");
- }
-
- @Override
- public String toString() {
- return store.toString();
- }
-
- };
- final List<ITableItem> items = Arrays.asList(createItem("A", 1),
- createItem("B", 2), createItem("C", 3));
- table.add("Header", null, recorder, false);
- table.render(body, items, createTotal("Sum", 6), resources, root);
- doc.close();
- assertEquals("init-footer-itemA-itemB-itemC-", recorder.toString());
- }
-
- @Test
- public void testInvisible() throws IOException {
- final IColumnRenderer column = new StubRenderer(
- CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)) {
-
- @Override
- public boolean init(List<? extends ITableItem> items,
- ICoverageNode total) {
- return false;
- }
-
- @Override
- public void footer(HTMLElement td, ICoverageNode total,
- Resources resources, ReportOutputFolder base) {
- fail();
- }
-
- @Override
- public void item(HTMLElement td, ITableItem item,
- Resources resources, ReportOutputFolder base) {
- fail();
- }
- };
- final List<ITableItem> items = Arrays.asList(createItem("A", 1));
- table.add("Header", null, column, false);
- table.render(body, items, createTotal("Sum", 1), resources, root);
- doc.close();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testTwoDefaultSorts() throws IOException {
- doc.close();
- table.add("Header1", null, new StubRenderer(
- CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), true);
- table.add("Header2", null, new StubRenderer(
- CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), true);
- }
-
- @Test
- public void testSortIds() throws Exception {
- final List<ITableItem> items = Arrays.asList(createItem("C", 3),
- createItem("E", 4), createItem("A", 1), createItem("D", 2));
- table.add("Forward", null, new StubRenderer(
- CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), false);
- table.add(
- "Reverse",
- null,
- new StubRenderer(CounterComparator.TOTALITEMS.reverse().on(
- CounterEntity.CLASS)), false);
- table.render(body, items, createTotal("Sum", 6), resources, root);
- doc.close();
-
- final HTMLSupport support = new HTMLSupport();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- // The elements in Column 1 are sorted in forward order:
- assertEquals("sortable",
- support.findStr(doc, "/html/body/table/thead/tr/td[1]/@class"));
- assertEquals("a",
- support.findStr(doc, "/html/body/table/thead/tr/td[1]/@id"));
- assertEquals("a2",
- support.findStr(doc, "/html/body/table/tbody/tr[1]/td[1]/@id"));
- assertEquals("a3",
- support.findStr(doc, "/html/body/table/tbody/tr[2]/td[1]/@id"));
- assertEquals("a0",
- support.findStr(doc, "/html/body/table/tbody/tr[3]/td[1]/@id"));
- assertEquals("a1",
- support.findStr(doc, "/html/body/table/tbody/tr[4]/td[1]/@id"));
-
- // The elements in Column 2 are sorted in reverse order:
- assertEquals("sortable",
- support.findStr(doc, "/html/body/table/thead/tr/td[2]/@class"));
- assertEquals("b",
- support.findStr(doc, "/html/body/table/thead/tr/td[2]/@id"));
- assertEquals("b1",
- support.findStr(doc, "/html/body/table/tbody/tr[1]/td[2]/@id"));
- assertEquals("b0",
- support.findStr(doc, "/html/body/table/tbody/tr[2]/td[2]/@id"));
- assertEquals("b3",
- support.findStr(doc, "/html/body/table/tbody/tr[3]/td[2]/@id"));
- assertEquals("b2",
- support.findStr(doc, "/html/body/table/tbody/tr[4]/td[2]/@id"));
- }
-
- @Test
- public void testDefaultSorting() throws Exception {
- final List<ITableItem> items = Arrays.asList(createItem("C", 3),
- createItem("E", 5), createItem("A", 1), createItem("D", 4),
- createItem("B", 2));
- table.add("Forward", null, new StubRenderer(
- CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), true);
- table.render(body, items, createTotal("Sum", 1), resources, root);
- doc.close();
-
- final HTMLSupport support = new HTMLSupport();
- final Document doc = support.parse(output.getFile("Test.html"));
-
- assertEquals("down sortable",
- support.findStr(doc, "/html/body/table/thead/tr/td[1]/@class"));
- assertEquals("A",
- support.findStr(doc, "/html/body/table/tbody/tr[1]/td[1]"));
- assertEquals("B",
- support.findStr(doc, "/html/body/table/tbody/tr[2]/td[1]"));
- assertEquals("C",
- support.findStr(doc, "/html/body/table/tbody/tr[3]/td[1]"));
- assertEquals("D",
- support.findStr(doc, "/html/body/table/tbody/tr[4]/td[1]"));
- assertEquals("E",
- support.findStr(doc, "/html/body/table/tbody/tr[5]/td[1]"));
- }
-
- private ITableItem createItem(final String name, final int count) {
- final ICoverageNode node = new CoverageNodeImpl(ElementType.GROUP, name) {
- {
- this.classCounter = CounterImpl.getInstance(count, 0);
- }
- };
- return new ITableItem() {
- public String getLinkLabel() {
- return name;
- }
-
- public String getLink(ReportOutputFolder base) {
- return name + ".html";
- }
-
- public String getLinkStyle() {
- return Resources.getElementStyle(node.getElementType());
- }
-
- public ICoverageNode getNode() {
- return node;
- }
- };
- }
-
- private ICoverageNode createTotal(final String name, final int count) {
- return new CoverageNodeImpl(ElementType.GROUP, name) {
- {
- this.classCounter = CounterImpl.getInstance(count, 0);
- }
- };
- }
-
- private static class StubRenderer implements IColumnRenderer {
-
- private final Comparator<ITableItem> comparator;
-
- StubRenderer(Comparator<ICoverageNode> comparator) {
- this.comparator = new TableItemComparator(comparator);
- }
-
- public boolean init(List<? extends ITableItem> items,
- ICoverageNode total) {
- return true;
- }
-
- public void footer(HTMLElement td, ICoverageNode total,
- Resources resources, ReportOutputFolder base) {
- }
-
- public void item(HTMLElement td, ITableItem item, Resources resources,
- ReportOutputFolder base) throws IOException {
- td.text(item.getLinkLabel());
- }
-
- public Comparator<ITableItem> getComparator() {
- return comparator;
- }
-
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.jacoco.core.analysis.CounterComparator; +import org.jacoco.core.analysis.CoverageNodeImpl; +import org.jacoco.core.analysis.ICoverageNode; +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.internal.ReportOutputFolder; +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.Resources; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Unit tests for {@link Table}. + */ +public class TableTest { + + private MemoryMultiReportOutput output; + + private ReportOutputFolder root; + + private Resources resources; + + private HTMLDocument doc; + + private HTMLElement body; + + private Table table; + + @Before + public void setup() throws IOException { + output = new MemoryMultiReportOutput(); + root = new ReportOutputFolder(output); + resources = new Resources(root); + doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8"); + doc.head().title(); + body = doc.body(); + table = new Table(); + } + + @After + public void teardown() throws IOException { + output.close(); + output.assertAllClosed(); + } + + @Test + public void testCallbackSequence() throws IOException { + final IColumnRenderer recorder = new StubRenderer( + CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)) { + + private final StringBuilder store = new StringBuilder(); + + @Override + public boolean init(List<? extends ITableItem> items, + ICoverageNode total) { + store.append("init-"); + return true; + } + + @Override + public void footer(HTMLElement td, ICoverageNode total, + Resources resources, ReportOutputFolder base) { + store.append("footer-"); + } + + @Override + public void item(HTMLElement td, ITableItem item, + Resources resources, ReportOutputFolder base) { + store.append("item").append(item.getLinkLabel()).append("-"); + } + + @Override + public String toString() { + return store.toString(); + } + + }; + final List<ITableItem> items = Arrays.asList(createItem("A", 1), + createItem("B", 2), createItem("C", 3)); + table.add("Header", null, recorder, false); + table.render(body, items, createTotal("Sum", 6), resources, root); + doc.close(); + assertEquals("init-footer-itemA-itemB-itemC-", recorder.toString()); + } + + @Test + public void testInvisible() throws IOException { + final IColumnRenderer column = new StubRenderer( + CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)) { + + @Override + public boolean init(List<? extends ITableItem> items, + ICoverageNode total) { + return false; + } + + @Override + public void footer(HTMLElement td, ICoverageNode total, + Resources resources, ReportOutputFolder base) { + fail(); + } + + @Override + public void item(HTMLElement td, ITableItem item, + Resources resources, ReportOutputFolder base) { + fail(); + } + }; + final List<ITableItem> items = Arrays.asList(createItem("A", 1)); + table.add("Header", null, column, false); + table.render(body, items, createTotal("Sum", 1), resources, root); + doc.close(); + } + + @Test(expected = IllegalStateException.class) + public void testTwoDefaultSorts() throws IOException { + doc.close(); + table.add("Header1", null, new StubRenderer( + CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), true); + table.add("Header2", null, new StubRenderer( + CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), true); + } + + @Test + public void testSortIds() throws Exception { + final List<ITableItem> items = Arrays.asList(createItem("C", 3), + createItem("E", 4), createItem("A", 1), createItem("D", 2)); + table.add("Forward", null, new StubRenderer( + CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), false); + table.add( + "Reverse", + null, + new StubRenderer(CounterComparator.TOTALITEMS.reverse().on( + CounterEntity.CLASS)), false); + table.render(body, items, createTotal("Sum", 6), resources, root); + doc.close(); + + final HTMLSupport support = new HTMLSupport(); + final Document doc = support.parse(output.getFile("Test.html")); + + // The elements in Column 1 are sorted in forward order: + assertEquals("sortable", + support.findStr(doc, "/html/body/table/thead/tr/td[1]/@class")); + assertEquals("a", + support.findStr(doc, "/html/body/table/thead/tr/td[1]/@id")); + assertEquals("a2", + support.findStr(doc, "/html/body/table/tbody/tr[1]/td[1]/@id")); + assertEquals("a3", + support.findStr(doc, "/html/body/table/tbody/tr[2]/td[1]/@id")); + assertEquals("a0", + support.findStr(doc, "/html/body/table/tbody/tr[3]/td[1]/@id")); + assertEquals("a1", + support.findStr(doc, "/html/body/table/tbody/tr[4]/td[1]/@id")); + + // The elements in Column 2 are sorted in reverse order: + assertEquals("sortable", + support.findStr(doc, "/html/body/table/thead/tr/td[2]/@class")); + assertEquals("b", + support.findStr(doc, "/html/body/table/thead/tr/td[2]/@id")); + assertEquals("b1", + support.findStr(doc, "/html/body/table/tbody/tr[1]/td[2]/@id")); + assertEquals("b0", + support.findStr(doc, "/html/body/table/tbody/tr[2]/td[2]/@id")); + assertEquals("b3", + support.findStr(doc, "/html/body/table/tbody/tr[3]/td[2]/@id")); + assertEquals("b2", + support.findStr(doc, "/html/body/table/tbody/tr[4]/td[2]/@id")); + } + + @Test + public void testDefaultSorting() throws Exception { + final List<ITableItem> items = Arrays.asList(createItem("C", 3), + createItem("E", 5), createItem("A", 1), createItem("D", 4), + createItem("B", 2)); + table.add("Forward", null, new StubRenderer( + CounterComparator.TOTALITEMS.on(CounterEntity.CLASS)), true); + table.render(body, items, createTotal("Sum", 1), resources, root); + doc.close(); + + final HTMLSupport support = new HTMLSupport(); + final Document doc = support.parse(output.getFile("Test.html")); + + assertEquals("down sortable", + support.findStr(doc, "/html/body/table/thead/tr/td[1]/@class")); + assertEquals("A", + support.findStr(doc, "/html/body/table/tbody/tr[1]/td[1]")); + assertEquals("B", + support.findStr(doc, "/html/body/table/tbody/tr[2]/td[1]")); + assertEquals("C", + support.findStr(doc, "/html/body/table/tbody/tr[3]/td[1]")); + assertEquals("D", + support.findStr(doc, "/html/body/table/tbody/tr[4]/td[1]")); + assertEquals("E", + support.findStr(doc, "/html/body/table/tbody/tr[5]/td[1]")); + } + + private ITableItem createItem(final String name, final int count) { + final ICoverageNode node = new CoverageNodeImpl(ElementType.GROUP, name) { + { + this.classCounter = CounterImpl.getInstance(count, 0); + } + }; + return new ITableItem() { + public String getLinkLabel() { + return name; + } + + public String getLink(ReportOutputFolder base) { + return name + ".html"; + } + + public String getLinkStyle() { + return Resources.getElementStyle(node.getElementType()); + } + + public ICoverageNode getNode() { + return node; + } + }; + } + + private ICoverageNode createTotal(final String name, final int count) { + return new CoverageNodeImpl(ElementType.GROUP, name) { + { + this.classCounter = CounterImpl.getInstance(count, 0); + } + }; + } + + private static class StubRenderer implements IColumnRenderer { + + private final Comparator<ITableItem> comparator; + + StubRenderer(Comparator<ICoverageNode> comparator) { + this.comparator = new TableItemComparator(comparator); + } + + public boolean init(List<? extends ITableItem> items, + ICoverageNode total) { + return true; + } + + public void footer(HTMLElement td, ICoverageNode total, + Resources resources, ReportOutputFolder base) { + } + + public void item(HTMLElement td, ITableItem item, Resources resources, + ReportOutputFolder base) throws IOException { + td.text(item.getLinkLabel()); + } + + public Comparator<ITableItem> getComparator() { + return comparator; + } + + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/LocalEntityResolver.java b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/LocalEntityResolver.java index 19408b40..f738c5ce 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/LocalEntityResolver.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/LocalEntityResolver.java @@ -1,45 +1,45 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 java.io.IOException;
-import java.io.InputStream;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- * Loader for local DTD definitions to avoid network access.
- */
-class LocalEntityResolver implements EntityResolver {
-
- private final Class<?> resourceDelegate;
-
- public LocalEntityResolver(Class<?> resourceDelegate) {
- this.resourceDelegate = resourceDelegate;
- }
-
- public InputSource resolveEntity(final String publicId, String systemId)
- throws SAXException, IOException {
- final int sep = systemId.lastIndexOf('/');
- if (sep != -1) {
- systemId = systemId.substring(sep + 1);
- }
- final InputStream in = resourceDelegate.getResourceAsStream(systemId);
- if (in == null) {
- throw new IOException("No local copy for " + systemId);
- }
- return new InputSource(in);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 java.io.IOException; +import java.io.InputStream; + +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Loader for local DTD definitions to avoid network access. + */ +class LocalEntityResolver implements EntityResolver { + + private final Class<?> resourceDelegate; + + public LocalEntityResolver(Class<?> resourceDelegate) { + this.resourceDelegate = resourceDelegate; + } + + public InputSource resolveEntity(final String publicId, String systemId) + throws SAXException, IOException { + final int sep = systemId.lastIndexOf('/'); + if (sep != -1) { + systemId = systemId.substring(sep + 1); + } + final InputStream in = resourceDelegate.getResourceAsStream(systemId); + if (in == null) { + throw new IOException("No local copy for " + systemId); + } + return new InputSource(in); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLDocumentTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLDocumentTest.java index 193c7fdc..95e4d02b 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLDocumentTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLDocumentTest.java @@ -1,93 +1,93 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-
-import org.junit.Test;
-
-/**
- * Unit tests for {@link XMLDocument}.
- */
-public class XMLDocumentTest {
-
- @Test
- public void testNoDoctype() throws IOException {
- StringWriter writer = new StringWriter();
- new XMLDocument("test", null, null, "UTF-8", false, writer).close();
- assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test/>",
- writer.toString());
- }
-
- @Test
- public void testNoDoctypeStandalone() throws IOException {
- StringWriter writer = new StringWriter();
- new XMLDocument("test", null, null, "UTF-8", true, writer).close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
- + "<test/>", writer.toString());
- }
-
- @Test
- public void testDoctype() throws IOException {
- StringWriter writer = new StringWriter();
- new XMLDocument("test", "sample", "sample.dtd", "UTF-8", false, writer)
- .close();
- assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<!DOCTYPE test PUBLIC \"sample\" \"sample.dtd\"><test/>",
- writer.toString());
- }
-
- @Test
- public void testDoctypeStandalone() throws IOException {
- StringWriter writer = new StringWriter();
- new XMLDocument("test", "sample", "sample.dtd", "UTF-8", true, writer)
- .close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
- + "<!DOCTYPE test PUBLIC \"sample\" \"sample.dtd\">"
- + "<test/>", writer.toString());
- }
-
- @Test
- public void testStream() throws IOException {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- new XMLDocument("test", null, null, "UTF-8", false, buffer).text(
- "\u00CD\u307e").close();
- assertEquals(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>\u00CD\u307e</test>",
- buffer.toString("UTF-8"));
- }
-
- @Test
- public void testClose() throws IOException {
- class CloseVerifier extends StringWriter {
-
- boolean closed = false;
-
- @Override
- public void close() throws IOException {
- closed = true;
- super.close();
- }
- }
- CloseVerifier verifier = new CloseVerifier();
- new XMLDocument("test", null, null, "UTF-8", false, verifier).close();
- assertTrue(verifier.closed);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringWriter; + +import org.junit.Test; + +/** + * Unit tests for {@link XMLDocument}. + */ +public class XMLDocumentTest { + + @Test + public void testNoDoctype() throws IOException { + StringWriter writer = new StringWriter(); + new XMLDocument("test", null, null, "UTF-8", false, writer).close(); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test/>", + writer.toString()); + } + + @Test + public void testNoDoctypeStandalone() throws IOException { + StringWriter writer = new StringWriter(); + new XMLDocument("test", null, null, "UTF-8", true, writer).close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + + "<test/>", writer.toString()); + } + + @Test + public void testDoctype() throws IOException { + StringWriter writer = new StringWriter(); + new XMLDocument("test", "sample", "sample.dtd", "UTF-8", false, writer) + .close(); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<!DOCTYPE test PUBLIC \"sample\" \"sample.dtd\"><test/>", + writer.toString()); + } + + @Test + public void testDoctypeStandalone() throws IOException { + StringWriter writer = new StringWriter(); + new XMLDocument("test", "sample", "sample.dtd", "UTF-8", true, writer) + .close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + + "<!DOCTYPE test PUBLIC \"sample\" \"sample.dtd\">" + + "<test/>", writer.toString()); + } + + @Test + public void testStream() throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + new XMLDocument("test", null, null, "UTF-8", false, buffer).text( + "\u00CD\u307e").close(); + assertEquals( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>\u00CD\u307e</test>", + buffer.toString("UTF-8")); + } + + @Test + public void testClose() throws IOException { + class CloseVerifier extends StringWriter { + + boolean closed = false; + + @Override + public void close() throws IOException { + closed = true; + super.close(); + } + } + CloseVerifier verifier = new CloseVerifier(); + new XMLDocument("test", null, null, "UTF-8", false, verifier).close(); + assertTrue(verifier.closed); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLElementTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLElementTest.java index e1746324..955bed94 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLElementTest.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLElementTest.java @@ -1,146 +1,146 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link XMLElement}.
- */
-public class XMLElementTest {
-
- private StringWriter buffer;
-
- private XMLElement root;
-
- @Before
- public void setUp() throws IOException {
- buffer = new StringWriter();
- root = new XMLElement(buffer, "root");
- root.beginOpenTag();
- }
-
- @Test
- public void testEmptyNode() throws IOException {
- root.close();
- // Second close has no effect:
- root.close();
- assertEquals("<root/>", buffer.toString());
- }
-
- @Test(expected = IOException.class)
- public void testAddAttributeToClosedNode() throws IOException {
- root.close();
- root.attr("attr", "value");
- }
-
- @Test(expected = IOException.class)
- public void testAddChildToClosedNode() throws IOException {
- root.close();
- root.element("child");
- }
-
- @Test(expected = IOException.class)
- public void testAddTextToClosedNode() throws IOException {
- root.close();
- root.text("text");
- }
-
- @Test
- public void testNestedElement() throws IOException {
- root.element("world");
- root.close();
- assertEquals("<root><world/></root>", buffer.toString());
- }
-
- @Test
- public void test2NestedElements() throws IOException {
- root.element("world");
- root.element("universe");
- root.close();
- assertEquals("<root><world/><universe/></root>", buffer.toString());
- }
-
- @Test
- public void testText() throws IOException {
- root.text("world");
- root.close();
- assertEquals("<root>world</root>", buffer.toString());
- }
-
- @Test
- public void testMixedContent() throws IOException {
- root.element("tag1");
- root.text("world");
- root.element("tag2");
- root.close();
- assertEquals("<root><tag1/>world<tag2/></root>", buffer.toString());
- }
-
- @Test
- public void testQuotedText() throws IOException {
- root.text("<black&white\">");
- root.close();
- assertEquals("<root><black&white"></root>",
- buffer.toString());
- }
-
- @Test
- public void testNullAttributes() throws IOException {
- root.attr("id", null);
- root.close();
- assertEquals("<root/>", buffer.toString());
- }
-
- @Test
- public void testStringAttributes() throws IOException {
- root.attr("id", "12345").attr("quote", "<\">");
- root.close();
- assertEquals("<root id=\"12345\" quote=\"<">\"/>",
- buffer.toString());
- }
-
- @Test
- public void testIntAttributes() throws IOException {
- root.attr("missed", 0).attr("total", 123);
- root.close();
- assertEquals("<root missed=\"0\" total=\"123\"/>", buffer.toString());
- }
-
- @Test
- public void testLongAttributes() throws IOException {
- root.attr("min", Long.MIN_VALUE).attr("max", Long.MAX_VALUE);
- root.close();
- assertEquals(
- "<root min=\"-9223372036854775808\" max=\"9223372036854775807\"/>",
- buffer.toString());
- }
-
- @Test(expected = IOException.class)
- public void testInvalidAttributeOutput1() throws IOException {
- root.text("text");
- root.attr("id", "12345");
- }
-
- @Test(expected = IOException.class)
- public void testInvalidAttributeOutput2() throws IOException {
- root.element("child");
- root.attr("id", "12345");
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link XMLElement}. + */ +public class XMLElementTest { + + private StringWriter buffer; + + private XMLElement root; + + @Before + public void setUp() throws IOException { + buffer = new StringWriter(); + root = new XMLElement(buffer, "root"); + root.beginOpenTag(); + } + + @Test + public void testEmptyNode() throws IOException { + root.close(); + // Second close has no effect: + root.close(); + assertEquals("<root/>", buffer.toString()); + } + + @Test(expected = IOException.class) + public void testAddAttributeToClosedNode() throws IOException { + root.close(); + root.attr("attr", "value"); + } + + @Test(expected = IOException.class) + public void testAddChildToClosedNode() throws IOException { + root.close(); + root.element("child"); + } + + @Test(expected = IOException.class) + public void testAddTextToClosedNode() throws IOException { + root.close(); + root.text("text"); + } + + @Test + public void testNestedElement() throws IOException { + root.element("world"); + root.close(); + assertEquals("<root><world/></root>", buffer.toString()); + } + + @Test + public void test2NestedElements() throws IOException { + root.element("world"); + root.element("universe"); + root.close(); + assertEquals("<root><world/><universe/></root>", buffer.toString()); + } + + @Test + public void testText() throws IOException { + root.text("world"); + root.close(); + assertEquals("<root>world</root>", buffer.toString()); + } + + @Test + public void testMixedContent() throws IOException { + root.element("tag1"); + root.text("world"); + root.element("tag2"); + root.close(); + assertEquals("<root><tag1/>world<tag2/></root>", buffer.toString()); + } + + @Test + public void testQuotedText() throws IOException { + root.text("<black&white\">"); + root.close(); + assertEquals("<root><black&white"></root>", + buffer.toString()); + } + + @Test + public void testNullAttributes() throws IOException { + root.attr("id", null); + root.close(); + assertEquals("<root/>", buffer.toString()); + } + + @Test + public void testStringAttributes() throws IOException { + root.attr("id", "12345").attr("quote", "<\">"); + root.close(); + assertEquals("<root id=\"12345\" quote=\"<">\"/>", + buffer.toString()); + } + + @Test + public void testIntAttributes() throws IOException { + root.attr("missed", 0).attr("total", 123); + root.close(); + assertEquals("<root missed=\"0\" total=\"123\"/>", buffer.toString()); + } + + @Test + public void testLongAttributes() throws IOException { + root.attr("min", Long.MIN_VALUE).attr("max", Long.MAX_VALUE); + root.close(); + assertEquals( + "<root min=\"-9223372036854775808\" max=\"9223372036854775807\"/>", + buffer.toString()); + } + + @Test(expected = IOException.class) + public void testInvalidAttributeOutput1() throws IOException { + root.text("text"); + root.attr("id", "12345"); + } + + @Test(expected = IOException.class) + public void testInvalidAttributeOutput2() throws IOException { + root.element("child"); + root.attr("id", "12345"); + } + +} diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLSupport.java b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLSupport.java index c441ae15..e7fe66d4 100644 --- a/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLSupport.java +++ b/org.jacoco.report.test/src/org/jacoco/report/internal/xml/XMLSupport.java @@ -1,90 +1,90 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.StringReader;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.w3c.dom.Document;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * Test utility to parse, validate and query XML documents.
- */
-public class XMLSupport {
-
- private final DocumentBuilder builder;
-
- private XPath xpath;
-
- public XMLSupport(Class<?> resourceDelegate)
- throws ParserConfigurationException {
- final DocumentBuilderFactory builderFactory = DocumentBuilderFactory
- .newInstance();
- builderFactory.setValidating(true);
- builder = builderFactory.newDocumentBuilder();
- builder.setEntityResolver(new LocalEntityResolver(resourceDelegate));
- builder.setErrorHandler(new ErrorHandler() {
- public void error(SAXParseException exception) throws SAXException {
- fail(exception.getMessage());
- }
-
- public void fatalError(SAXParseException exception)
- throws SAXException {
- fail(exception.getMessage());
- }
-
- public void warning(SAXParseException exception)
- throws SAXException {
- fail(exception.getMessage());
- }
- });
- }
-
- private XPath getXPath() {
- if (xpath == null) {
- xpath = XPathFactory.newInstance().newXPath();
- }
- return xpath;
- }
-
- public Document parse(String document) throws SAXException, IOException,
- ParserConfigurationException {
- return builder.parse(new InputSource(new StringReader(document)));
- }
-
- public Document parse(byte[] document) throws SAXException, IOException,
- ParserConfigurationException {
- return builder
- .parse(new InputSource(new ByteArrayInputStream(document)));
- }
-
- public String findStr(final Document doc, final String query)
- throws XPathExpressionException {
- return (String) getXPath().evaluate(query, doc, XPathConstants.STRING);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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.fail; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * Test utility to parse, validate and query XML documents. + */ +public class XMLSupport { + + private final DocumentBuilder builder; + + private XPath xpath; + + public XMLSupport(Class<?> resourceDelegate) + throws ParserConfigurationException { + final DocumentBuilderFactory builderFactory = DocumentBuilderFactory + .newInstance(); + builderFactory.setValidating(true); + builder = builderFactory.newDocumentBuilder(); + builder.setEntityResolver(new LocalEntityResolver(resourceDelegate)); + builder.setErrorHandler(new ErrorHandler() { + public void error(SAXParseException exception) throws SAXException { + fail(exception.getMessage()); + } + + public void fatalError(SAXParseException exception) + throws SAXException { + fail(exception.getMessage()); + } + + public void warning(SAXParseException exception) + throws SAXException { + fail(exception.getMessage()); + } + }); + } + + private XPath getXPath() { + if (xpath == null) { + xpath = XPathFactory.newInstance().newXPath(); + } + return xpath; + } + + public Document parse(String document) throws SAXException, IOException, + ParserConfigurationException { + return builder.parse(new InputSource(new StringReader(document))); + } + + public Document parse(byte[] document) throws SAXException, IOException, + ParserConfigurationException { + return builder + .parse(new InputSource(new ByteArrayInputStream(document))); + } + + public String findStr(final Document doc, final String query) + throws XPathExpressionException { + return (String) getXPath().evaluate(query, doc, XPathConstants.STRING); + } + +} |