You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenericCoverageMediumTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. import java.io.File;
  22. import java.io.IOException;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.sonar.api.batch.fs.InputFile;
  28. import org.sonar.scanner.mediumtest.AnalysisResult;
  29. import org.sonar.scanner.mediumtest.ScannerMediumTester;
  30. import org.sonar.xoo.XooPlugin;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. public class GenericCoverageMediumTest {
  33. private final List<String> logs = new ArrayList<>();
  34. @Rule
  35. public ScannerMediumTester tester = new ScannerMediumTester()
  36. .registerPlugin("xoo", new XooPlugin())
  37. .addDefaultQProfile("xoo", "Sonar Way");
  38. @Test
  39. public void singleReport() throws IOException {
  40. File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
  41. AnalysisResult result = tester
  42. .setLogOutput((msg, level) -> logs.add(msg))
  43. .newAnalysis(new File(projectDir, "sonar-project.properties"))
  44. .property("sonar.coverageReportPaths", "coverage.xml")
  45. .execute();
  46. InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
  47. assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
  48. assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
  49. assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
  50. assertThat(result.coverageFor(noConditions, 7).getHits()).isFalse();
  51. InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
  52. assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
  53. assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
  54. assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(1);
  55. assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
  56. }
  57. @Test
  58. public void twoReports() throws IOException {
  59. File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
  60. AnalysisResult result = tester
  61. .setLogOutput((msg, level) -> logs.add(msg))
  62. .newAnalysis(new File(projectDir, "sonar-project.properties"))
  63. .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml")
  64. .execute();
  65. InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
  66. assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
  67. assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
  68. assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
  69. assertThat(result.coverageFor(noConditions, 7).getHits()).isTrue();
  70. InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
  71. assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
  72. assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
  73. assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(2);
  74. assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
  75. }
  76. }