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.mediumtest.coverage;
23 import java.io.IOException;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.sonar.api.batch.fs.InputFile;
28 import org.sonar.api.measures.CoreMetrics;
29 import org.sonar.scanner.mediumtest.ScannerMediumTester;
30 import org.sonar.scanner.mediumtest.TaskResult;
31 import org.sonar.xoo.XooPlugin;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.assertj.core.api.Assertions.tuple;
36 public class GenericCoverageMediumTest {
38 public ScannerMediumTester tester = ScannerMediumTester.builder()
39 .registerPlugin("xoo", new XooPlugin())
40 .addDefaultQProfile("xoo", "Sonar Way")
44 public void prepare() {
54 public void singleReport() throws IOException {
56 File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage");
58 TaskResult result = tester
59 .newScanTask(new File(projectDir, "sonar-project.properties"))
60 .property("sonar.coverageReportPaths", "coverage.xml")
63 InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
64 assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
65 assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
66 assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
68 assertThat(result.coverageFor(noConditions, 7).getHits()).isFalse();
70 assertThat(result.allMeasures().get(noConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value")
72 tuple(CoreMetrics.LINES_TO_COVER_KEY, 2, ""),
73 tuple(CoreMetrics.UNCOVERED_LINES_KEY, 1, ""),
74 tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "6=1;7=0"));
76 InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
77 assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
78 assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
79 assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(1);
81 assertThat(result.allMeasures().get(withConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value")
83 tuple(CoreMetrics.LINES_TO_COVER_KEY, 1, ""),
84 tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0, ""),
85 tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "3=1"),
86 tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2, ""),
87 tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 1, ""),
88 tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "3=2"),
89 tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "3=1")
95 public void twoReports() throws IOException {
97 File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage");
99 TaskResult result = tester
100 .newScanTask(new File(projectDir, "sonar-project.properties"))
101 .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml")
104 InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
105 assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
106 assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
107 assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
109 assertThat(result.coverageFor(noConditions, 7).getHits()).isTrue();
111 assertThat(result.allMeasures().get(noConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value")
113 tuple(CoreMetrics.LINES_TO_COVER_KEY, 2, ""),
114 tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0, ""),
115 tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "6=1;7=1"));
117 InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
118 assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
119 assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
120 assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(2);
122 assertThat(result.allMeasures().get(withConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value")
124 tuple(CoreMetrics.LINES_TO_COVER_KEY, 1, ""),
125 tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0, ""),
126 tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "3=2"),
127 tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2, ""),
128 tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 0, ""),
129 tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "3=2"),
130 tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "3=2")