3 * Copyright (C) 2009-2019 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 java.nio.charset.StandardCharsets;
25 import java.util.HashMap;
27 import org.apache.commons.io.FileUtils;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.TemporaryFolder;
31 import org.sonar.api.batch.sensor.internal.SensorContextTester;
32 import org.sonar.api.config.Encryption;
33 import org.sonar.api.config.PropertyDefinitions;
34 import org.sonar.api.config.Settings;
35 import org.sonar.api.config.internal.MapSettings;
36 import org.sonar.api.utils.log.LogTester;
37 import org.sonar.api.utils.log.LoggerLevel;
38 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
39 import org.sonar.scanner.config.DefaultConfiguration;
40 import org.sonar.scanner.deprecated.test.TestPlanBuilder;
41 import org.sonar.scanner.scan.ProjectSettings;
43 import static org.assertj.core.api.Assertions.assertThat;
44 import static org.mockito.Mockito.mock;
46 public class GenericTestExecutionSensorTest {
49 public TemporaryFolder temp = new TemporaryFolder();
52 public LogTester logTester = new LogTester();
55 public void logWhenDeprecatedPropsAreUsed() throws IOException {
56 File basedir = temp.newFolder();
57 File report = new File(basedir, "report.xml");
58 FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>", StandardCharsets.UTF_8);
59 SensorContextTester context = SensorContextTester.create(basedir);
61 Map<String, String> settings = new HashMap<>();
62 settings.put(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml");
63 PropertyDefinitions defs = new PropertyDefinitions(GenericTestExecutionSensor.properties());
64 DefaultConfiguration config = new ProjectSettings(defs, new Encryption(null), mock(GlobalAnalysisMode.class), settings);
66 new GenericTestExecutionSensor(mock(TestPlanBuilder.class), config).execute(context);
67 assertThat(logTester.logs(LoggerLevel.WARN)).contains(
68 "Using 'unitTest' as root element of the report is deprecated. Please change to 'testExecutions'.",
69 "Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.");
71 assertThat(logTester.logs(LoggerLevel.INFO)).contains(
72 "Imported test execution data for 0 files",
73 "Test execution data ignored for 1 unknown files, including:\nA.java");