aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.report.test/src/org/jacoco/report/FileMultiReportOutputTest.java
blob: 7e1409b5a878282b348a3ea94f8cde2a59827710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*******************************************************************************
 * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * 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());
		actual.close();
	}

	@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");
	}

}