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.8KB

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