use of org.sonar.ce.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method getLevel_throws_IEA_if_error_threshold_is_not_parsable_long.
@Test
public void getLevel_throws_IEA_if_error_threshold_is_not_parsable_long() {
Metric metric = createMetric(WORK_DUR);
Measure measure = newMeasureBuilder().create(60L, null);
assertThatThrownBy(() -> underTest.evaluate(createCondition(metric, LESS_THAN, "polop"), measure)).isInstanceOf(IllegalArgumentException.class).hasMessage("Quality Gate: Unable to parse value 'polop' to compare against name");
}
use of org.sonar.ce.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method test_input_numbers.
@Test
public void test_input_numbers() {
try {
Metric metric = createMetric(FLOAT);
Measure measure = newMeasureBuilder().create(10.2d, 1, null);
underTest.evaluate(createCondition(metric, LESS_THAN, "20"), measure);
} catch (NumberFormatException ex) {
fail();
}
try {
Metric metric = createMetric(INT);
Measure measure = newMeasureBuilder().create(5, null);
underTest.evaluate(createCondition(metric, LESS_THAN, "20.1"), measure);
} catch (NumberFormatException ex) {
fail();
}
try {
Metric metric = createMetric(PERCENT);
Measure measure = newMeasureBuilder().create(10.2d, 1, null);
underTest.evaluate(createCondition(metric, LESS_THAN, "20.1"), measure);
} catch (NumberFormatException ex) {
fail();
}
}
use of org.sonar.ce.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method fail_when_metric_is_not_supported.
@Test
@UseDataProvider("unsupportedMetricTypes")
public void fail_when_metric_is_not_supported(MetricType metricType) {
Metric metric = createMetric(metricType);
Measure measure = newMeasureBuilder().create("3.14159265358");
assertThatThrownBy(() -> underTest.evaluate(createCondition(metric, LESS_THAN, "1.60217657"), measure)).isInstanceOf(IllegalArgumentException.class).hasMessage(String.format("Conditions on MetricType %s are not supported", metricType));
}
use of org.sonar.ce.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method test_condition_on_numeric_new_metric.
@Test
@UseDataProvider("numericNewMetricTypes")
public void test_condition_on_numeric_new_metric(MetricType metricType) {
Metric metric = createNewMetric(metricType);
Measure measure = newMeasureBuilder().setVariation(3d).createNoValue();
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK);
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR);
}
use of org.sonar.ce.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method test_condition_on_rating.
@Test
public void test_condition_on_rating() {
Metric metric = createMetric(RATING);
Measure measure = newMeasureBuilder().create(4, "D");
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "4"), measure)).hasLevel(OK).hasValue(4);
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR).hasValue(4);
}
Aggregations