use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class DistributionFormulaExecutionTest method add_measures.
@Test
public void add_measures() {
ReportComponent project = builder(PROJECT, 1).addChildren(builder(DIRECTORY, 11).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build(), builder(Component.Type.FILE, 1112).build()).build()).build(), builder(DIRECTORY, 12).addChildren(builder(DIRECTORY, 121).addChildren(builder(Component.Type.FILE, 1211).build()).build()).build()).build();
treeRootHolder.setRoot(project);
measureRepository.addRawMeasure(1111, FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=3;3.5=5;6.5=9"));
measureRepository.addRawMeasure(1112, FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=0;3.5=2;6.5=1"));
measureRepository.addRawMeasure(1211, FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=1;3.5=3;6.5=2"));
new PathAwareCrawler<>(underTest).visit(project);
assertThat(toEntries(measureRepository.getAddedRawMeasures(1))).containsOnly(entryOf(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=4;3.5=10;6.5=12")));
assertThat(toEntries(measureRepository.getAddedRawMeasures(11))).containsOnly(entryOf(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=3;3.5=7;6.5=10")));
assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=3;3.5=7;6.5=10")));
assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(1112)).isEmpty();
assertThat(toEntries(measureRepository.getAddedRawMeasures(12))).containsOnly(entryOf(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=1;3.5=3;6.5=2")));
assertThat(toEntries(measureRepository.getAddedRawMeasures(121))).containsOnly(entryOf(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, newMeasureBuilder().create("0.5=1;3.5=3;6.5=2")));
assertThat(measureRepository.getAddedRawMeasures(1211)).isEmpty();
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class SumFormulaExecutionTest method not_add_measures_when_no_data_on_file.
@Test
public void not_add_measures_when_no_data_on_file() {
ReportComponent project = builder(PROJECT, 1).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build()).build()).build();
treeRootHolder.setRoot(project);
new PathAwareCrawler<>(underTest).visit(project);
assertThat(measureRepository.getAddedRawMeasures(1)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(111)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class ReportFormulaExecutorComponentVisitorTest method fail_on_project_without_children_already_having_computed_measure.
@Test
public void fail_on_project_without_children_already_having_computed_measure() {
ReportComponent root = builder(PROJECT, ROOT_REF).build();
treeRootHolder.setRoot(root);
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(10));
// expectedException.expectCause(hasType(UnsupportedOperationException.class)
// .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY)));
assertThatThrownBy(() -> {
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(root);
}).hasCause(new UnsupportedOperationException(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY)));
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class ReportFormulaExecutorComponentVisitorTest method compute_measure_on_project_without_children.
@Test
public void compute_measure_on_project_without_children() {
ReportComponent root = builder(PROJECT, ROOT_REF).build();
treeRootHolder.setRoot(root);
measureRepository.addRawMeasure(ROOT_REF, LINES_KEY, newMeasureBuilder().create(10));
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(root);
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly(entryOf(NCLOC_KEY, newMeasureBuilder().create(10)));
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class ReportFormulaExecutorComponentVisitorTest method measures_are_0_when_there_is_no_input_measure.
@Test
public void measures_are_0_when_there_is_no_input_measure() {
ReportComponent project = ReportComponent.builder(PROJECT, ROOT_REF).addChildren(ReportComponent.builder(DIRECTORY, DIRECTORY_1_REF).addChildren(builder(Component.Type.FILE, FILE_1_REF).build()).build()).build();
treeRootHolder.setRoot(project);
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(project);
assertAddedRawMeasure(ROOT_REF, 0);
assertAddedRawMeasure(DIRECTORY_1_REF, 0);
assertAddedRawMeasure(FILE_1_REF, 0);
}
Aggregations