1/******************************************************************************* 2 * Copyright (c) 2009, 2017 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.cli.internal.commands; 13 14import java.io.File; 15import java.io.FileOutputStream; 16import java.io.IOException; 17 18import org.jacoco.cli.internal.CommandTestBase; 19import org.jacoco.core.data.ExecutionData; 20import org.jacoco.core.data.ExecutionDataWriter; 21import org.jacoco.core.data.SessionInfo; 22import org.junit.Rule; 23import org.junit.Test; 24import org.junit.rules.TemporaryFolder; 25 26/** 27 * Unit tests for {@link ExecInfo}. 28 */ 29public class ExecInfoTest extends CommandTestBase { 30 31 @Rule 32 public TemporaryFolder tmp = new TemporaryFolder(); 33 34 @Test 35 public void should_print_usage_when_invalid_argument_is_given() 36 throws Exception { 37 execute("execinfo", "-invalid"); 38 39 assertFailure(); 40 assertContains("\"-invalid\" is not a valid option", err); 41 assertContains("java -jar jacococli.jar execinfo [<execfiles> ...]", 42 err); 43 } 44 45 @Test 46 public void should_print_execution_data_info() throws Exception { 47 File execfile = createExecFile(); 48 49 execute("execinfo", execfile.getAbsolutePath()); 50 51 assertOk(); 52 assertContains("[INFO] Loading exec file " + execfile.getAbsolutePath(), 53 out); 54 assertContains("CLASS ID HITS/PROBES CLASS NAME", out); 55 assertContains("Session \"testid\":", out); 56 assertContains("0000000000001234 2 of 3 foo/MyClass", out); 57 } 58 59 private File createExecFile() throws IOException { 60 File f = new File(tmp.getRoot(), "test.exec"); 61 final FileOutputStream out = new FileOutputStream(f); 62 final ExecutionDataWriter writer = new ExecutionDataWriter(out); 63 writer.visitSessionInfo(new SessionInfo("testid", 1, 2)); 64 writer.visitClassExecution(new ExecutionData(0x1234, "foo/MyClass", 65 new boolean[] { false, true, true })); 66 out.close(); 67 return f; 68 } 69 70} 71