3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.scanner.genericcoverage;
23 import java.io.IOException;
24 import org.apache.commons.io.FileUtils;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.TemporaryFolder;
28 import org.sonar.api.batch.sensor.internal.SensorContextTester;
29 import org.sonar.api.config.MapSettings;
30 import org.sonar.api.config.PropertyDefinitions;
31 import org.sonar.api.config.Settings;
32 import org.sonar.api.utils.log.LogTester;
33 import org.sonar.api.utils.log.LoggerLevel;
34 import org.sonar.scanner.deprecated.test.TestPlanBuilder;
36 import static org.assertj.core.api.Assertions.assertThat;
37 import static org.mockito.Mockito.mock;
39 public class GenericTestExecutionSensorTest {
42 public TemporaryFolder temp = new TemporaryFolder();
45 public LogTester logTester = new LogTester();
48 public void logWhenDeprecatedPropsAreUsed() throws IOException {
49 File basedir = temp.newFolder();
50 File report = new File(basedir, "report.xml");
51 FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>");
52 SensorContextTester context = SensorContextTester.create(basedir);
53 Settings settings = new MapSettings(new PropertyDefinitions(GenericTestExecutionSensor.properties()));
54 settings.setProperty(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml");
55 context.setSettings(settings);
56 new GenericTestExecutionSensor(mock(TestPlanBuilder.class)).execute(context);
57 assertThat(logTester.logs(LoggerLevel.WARN)).contains(
58 "Using 'unitTest' as root element of the report is deprecated. Please change to 'testExecutions'.",
59 "Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.");
61 assertThat(logTester.logs(LoggerLevel.INFO)).contains(
62 "Imported test execution data for 0 files",
63 "Test execution data ignored for 1 unknown files, including:\nA.java");