@Test
  public void shouldParseReport() throws Exception {
    DefaultFileSystem fs = new DefaultFileSystem();
    File srcFile = TestUtils.getResource(TEST_DIR + "example/File.as");
    InputFile inputFile =
        new DefaultInputFile(srcFile.getName())
            .setLanguage(Flex.KEY)
            .setType(InputFile.Type.MAIN)
            .setAbsolutePath(srcFile.getAbsolutePath());

    fs.add(inputFile);

    Sensor sensor =
        newSensorWithProperty(
            FlexPlugin.COBERTURA_REPORT_PATH,
            TestUtils.getResource(TEST_DIR + "coverage.xml").getPath(),
            fs);
    sensor.analyse(project, context);

    verify(context).saveMeasure(eq(inputFile), eq(new Measure(CoreMetrics.LINES_TO_COVER, 2.0)));
    verify(context).saveMeasure(eq(inputFile), eq(new Measure(CoreMetrics.UNCOVERED_LINES, 2.0)));
    verify(context)
        .saveMeasure(
            eq(inputFile), eq(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "1=0;7=0")));
    verify(context)
        .saveMeasure(eq(inputFile), eq(new Measure(CoreMetrics.CONDITIONS_TO_COVER, 2.0)));
    verify(context)
        .saveMeasure(eq(inputFile), eq(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, 1.0)));
    verify(context)
        .saveMeasure(eq(inputFile), eq(new Measure(CoreMetrics.CONDITIONS_BY_LINE, "1=2")));
    verify(context)
        .saveMeasure(eq(inputFile), eq(new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "1=1")));
  }
  @Test
  public void reportNotFound() {
    Sensor sensor =
        newSensorWithProperty(
            FlexPlugin.COBERTURA_REPORT_PATH, "/fake/path", new DefaultFileSystem());
    sensor.analyse(project, context);

    verify(context, never())
        .saveMeasure(any(org.sonar.api.resources.File.class), any(Metric.class), anyDouble());
  }
Example #3
0
 private void executeSensor(SensorContext context, Sensor sensor) {
   eventBus.fireEvent(new SensorExecutionEvent(sensor, true));
   executeMavenPlugin(sensor);
   sensor.analyse(module, context);
   eventBus.fireEvent(new SensorExecutionEvent(sensor, false));
 }