]> source.dussan.org Git - sonarqube.git/blob
1fc4d93676ca2a93c09fd3c01ba044bcdf4e708a
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2019 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.scanner.mediumtest.coverage;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.sonar.api.batch.fs.InputFile;
29 import org.sonar.scanner.mediumtest.AnalysisResult;
30 import org.sonar.scanner.mediumtest.ScannerMediumTester;
31 import org.sonar.xoo.XooPlugin;
32
33 import static org.assertj.core.api.Assertions.assertThat;
34
35 public class GenericCoverageMediumTest {
36   private final List<String> logs = new ArrayList<>();
37   
38   @Rule
39   public ScannerMediumTester tester = new ScannerMediumTester()
40     .registerPlugin("xoo", new XooPlugin())
41     .addDefaultQProfile("xoo", "Sonar Way");
42
43   @Test
44   public void singleReport() throws IOException {
45
46     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
47
48     AnalysisResult result = tester
49       .setLogOutput((msg, level) -> logs.add(msg))
50       .newAnalysis(new File(projectDir, "sonar-project.properties"))
51       .property("sonar.coverageReportPaths", "coverage.xml")
52       .execute();
53
54     InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
55     assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
56     assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
57     assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
58
59     assertThat(result.coverageFor(noConditions, 7).getHits()).isFalse();
60
61     InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
62     assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
63     assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
64     assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(1);
65
66     assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
67
68   }
69   
70   @Test
71   public void warnAboutDeprecatedProperty() {
72     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
73
74     tester
75       .setLogOutput((msg, level) -> logs.add(msg))
76       .newAnalysis(new File(projectDir, "sonar-project.properties"))
77       .property("sonar.genericcoverage.reportPath", "coverage.xml")
78       .execute();
79       
80       
81     assertThat(logs).anyMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
82   }
83
84   @Test
85   public void twoReports() throws IOException {
86
87     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
88
89     AnalysisResult result = tester
90       .setLogOutput((msg, level) -> logs.add(msg))
91       .newAnalysis(new File(projectDir, "sonar-project.properties"))
92       .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml")
93       .execute();
94
95     InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
96     assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
97     assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
98     assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
99
100     assertThat(result.coverageFor(noConditions, 7).getHits()).isTrue();
101
102     InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
103     assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
104     assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
105     assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(2);
106
107     assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
108   }
109   
110 }