Search in sources :

Example 11 with MeasureComputer

use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method fail_with_ISE_when_two_measure_computers_generate_the_same_output_metric.

@Test
public void fail_with_ISE_when_two_measure_computers_generate_the_same_output_metric() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Output metric 'metric1' is already defined by another measure computer 'TestMeasureComputer'");
    MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)), newMeasureComputer(array(CLASSES_KEY), array(NEW_METRIC_1)) };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute();
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.server.computation.task.step.ComputationStep) Test(org.junit.Test)

Example 12 with MeasureComputer

use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method sort_computers.

@Test
public void sort_computers() throws Exception {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers = new MeasureComputer[] { measureComputer1, measureComputer2, measureComputer3 };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute();
    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
}
Also used : MeasureComputerWrapper(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.server.computation.task.step.ComputationStep) Test(org.junit.Test)

Example 13 with MeasureComputer

use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method sort_computers_when_one_computer_has_no_input_metric.

@Test
public void sort_computers_when_one_computer_has_no_input_metric() throws Exception {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(new String[] {}, array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers = new MeasureComputer[] { measureComputer1, measureComputer2, measureComputer3 };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute();
    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
}
Also used : MeasureComputerWrapper(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.server.computation.task.step.ComputationStep) Test(org.junit.Test)

Example 14 with MeasureComputer

use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric.

@Test
public void fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Metric 'metric1' cannot be used as an output metric as no plugin declare this metric");
    MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)) };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, computers);
    underTest.execute();
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.server.computation.task.step.ComputationStep) Test(org.junit.Test)

Aggregations

MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)14 Test (org.junit.Test)12 ComputationStep (org.sonar.server.computation.task.step.ComputationStep)11 MeasureComputerWrapper (org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper)5 MeasureComputerContextImpl (org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerContextImpl)1 MeasureComputerDefinitionImpl (org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerDefinitionImpl)1 VisitorsCrawler (org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler)1