use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class NewMaintainabilityMeasuresVisitorTest method leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt.
@Test
public void leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt() {
when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
Component file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build();
treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(file).build()).build());
Measure newDebtMeasure = createNewDebtMeasure(50);
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
// 4 lines file, only first one is not ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
// first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
setNewLines(file, 3, 4);
underTest.visit(treeRootHolder.getRoot());
assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33);
assertNewDebtRatioValues(111, 83.33);
assertNewDebtRatioValues(ROOT_REF, 83.33);
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class NewMaintainabilityMeasuresVisitorTest method setupOneFileAloneInAProject.
private void setupOneFileAloneInAProject(int newDebt, Flag isUnitTest, Flag withNclocLines, Flag withNewLines) {
checkArgument(isUnitTest == Flag.UT_FILE || isUnitTest == Flag.SRC_FILE);
checkArgument(withNclocLines == Flag.WITH_NCLOC || withNclocLines == Flag.NO_NCLOC || withNclocLines == Flag.MISSING_MEASURE_NCLOC);
checkArgument(withNewLines == Flag.WITH_NEW_LINES || withNewLines == Flag.NO_NEW_LINES);
Component file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build();
treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(file).build());
Measure newDebtMeasure = createNewDebtMeasure(newDebt);
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
if (withNclocLines == Flag.WITH_NCLOC) {
// 4 lines file, only first one is not ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
} else if (withNclocLines == Flag.NO_NCLOC) {
// 4 lines file, none of which is ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNoNclocDataMeasure(4));
}
if (withNewLines == Flag.WITH_NEW_LINES) {
// 2 last lines are new
setNewLines(file, 3, 4);
}
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class SecurityReviewMeasuresVisitorTest method verifySecurityReviewRating.
private void verifySecurityReviewRating(int componentRef, Rating rating) {
Measure measure = measureRepository.getAddedRawMeasure(componentRef, SECURITY_REVIEW_RATING_KEY).get();
assertThat(measure.getIntValue()).isEqualTo(rating.getIndex());
assertThat(measure.getData()).isEqualTo(rating.name());
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method condition_is_always_ok_when_measure_is_noValue.
@Test
public void condition_is_always_ok_when_measure_is_noValue() {
for (MetricType metricType : from(asList(values())).filter(not(in(ImmutableSet.of(BOOL, DATA, DISTRIB, STRING))))) {
Metric metric = createMetric(metricType);
Measure measure = newMeasureBuilder().createNoValue();
assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.2"), measure)).hasLevel(OK);
}
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method fail_when_condition_on_leak_period_is_using_unsupported_metric.
@Test
public void fail_when_condition_on_leak_period_is_using_unsupported_metric() {
Metric metric = createNewMetric(LEVEL);
Measure measure = newMeasureBuilder().setVariation(0d).createNoValue();
assertThatThrownBy(() -> underTest.evaluate(new Condition(metric, LESS_THAN.getDbValue(), "3"), measure)).isInstanceOf(IllegalArgumentException.class).hasMessage("Unsupported metric type LEVEL");
}
Aggregations