1/*******************************************************************************
2 * Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *    Marc R. Hoffmann - initial API and implementation
10 *
11 *******************************************************************************/
12package org.jacoco.report.csv;
13
14import static org.junit.Assert.assertEquals;
15
16import java.io.BufferedReader;
17import java.io.StringReader;
18import java.io.StringWriter;
19
20import org.jacoco.report.IReportGroupVisitor;
21import org.jacoco.report.JavaNames;
22import org.jacoco.report.ReportStructureTestDriver;
23import org.junit.Before;
24import org.junit.Test;
25
26/**
27 * Unit tests for {@link CSVGroupHandler}.
28 */
29public class CSVGroupHandlerTest {
30
31	private IReportGroupVisitor handler;
32
33	private StringWriter result;
34
35	private ReportStructureTestDriver driver;
36
37	@Before
38	public void setup() throws Exception {
39		result = new StringWriter();
40		final DelimitedWriter dw = new DelimitedWriter(result);
41		final ClassRowWriter rw = new ClassRowWriter(dw, new JavaNames());
42		handler = new CSVGroupHandler(rw);
43		driver = new ReportStructureTestDriver();
44	}
45
46	@Test
47	public void testVisitBundle() throws Exception {
48		driver.sendBundle(handler);
49		final BufferedReader reader = getResultReader();
50		reader.readLine();
51		assertEquals(
52				"bundle,org.jacoco.example,FooClass,10,15,1,2,0,3,1,2,0,1",
53				reader.readLine());
54	}
55
56	@Test
57	public void testVisitGroup() throws Exception {
58		driver.sendGroup(handler);
59		final BufferedReader reader = getResultReader();
60		reader.readLine();
61		assertEquals(
62				"group/bundle,org.jacoco.example,FooClass,10,15,1,2,0,3,1,2,0,1",
63				reader.readLine());
64	}
65
66	private BufferedReader getResultReader() {
67		return new BufferedReader(new StringReader(result.toString()));
68	}
69
70}
71