1 /******************************************************************************* 2 * Copyright (c) 2009, 2018 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 *******************************************************************************/ 12 package org.jacoco.report; 13 14 import static org.junit.Assert.assertEquals; 15 16 import java.io.File; 17 import java.io.FileInputStream; 18 import java.io.IOException; 19 import java.io.InputStream; 20 import java.io.OutputStream; 21 22 import org.junit.Rule; 23 import org.junit.Test; 24 import org.junit.rules.TemporaryFolder; 25 26 /** 27 * Unit tests for {@link FileMultiReportOutput}. 28 */ 29 public class FileMultiReportOutputTest { 30 31 @Rule 32 public TemporaryFolder folder = new TemporaryFolder(); 33 34 @Test 35 public void testCreateFileWithDirectories() throws IOException { 36 final IMultiReportOutput output = new FileMultiReportOutput( 37 folder.getRoot()); 38 final OutputStream stream = output.createFile("a/b/c/test"); 39 stream.write(1); 40 stream.write(2); 41 stream.write(3); 42 stream.close(); 43 output.close(); 44 45 final InputStream actual = new FileInputStream(new File( 46 folder.getRoot(), "a/b/c/test")); 47 assertEquals(1, actual.read()); 48 assertEquals(2, actual.read()); 49 assertEquals(3, actual.read()); 50 assertEquals(-1, actual.read()); 51 actual.close(); 52 } 53 54 @Test(expected = IOException.class) 55 public void testCreateFileNegative() throws IOException { 56 folder.newFile("a"); 57 final IMultiReportOutput output = new FileMultiReportOutput( 58 folder.getRoot()); 59 output.createFile("a/b/c/test"); 60 } 61 62 } 63