Search in sources :

Example 6 with MetricImpl

use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class MeasureDtoToMeasureTest method toMeasure_should_not_loose_decimals_of_float_values.

@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
    MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
    MeasureDto measureDto = new MeasureDto().setValue(0.12345);
    Optional<Measure> measure = underTest.toMeasure(measureDto, metric);
    assertThat(measure.get().getDoubleValue()).isEqualTo(0.12345, Offset.offset(0.000001));
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Test(org.junit.Test)

Example 7 with MetricImpl

use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class MeasureRepositoryImplTest method update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE.

@Test
@UseDataProvider("measures")
public void update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE(Measure measure) {
    for (Metric.MetricType metricType : Metric.MetricType.values()) {
        if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == Measure.ValueType.NO_VALUE) {
            continue;
        }
        try {
            final MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
            underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
            underTest.update(FILE_COMPONENT, metric, measure);
            fail("An IllegalArgumentException should have been raised");
        } catch (IllegalArgumentException e) {
            assertThat(e).hasMessage(format("Measure's ValueType (%s) is not consistent with the Metric's ValueType (%s)", measure.getValueType(), metricType.getValueType()));
        }
    }
}
Also used : MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 8 with MetricImpl

use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class MeasureRepositoryImplTest method update_accepts_NO_VALUE_as_measure_arg.

@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
    for (Metric.MetricType metricType : Metric.MetricType.values()) {
        MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
        underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
        underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
    }
}
Also used : MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 9 with MetricImpl

use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class MapBasedRawMeasureRepositoryTest method update_accepts_NO_VALUE_as_measure_arg.

@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
    for (Metric.MetricType metricType : Metric.MetricType.values()) {
        MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
        underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
        underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
    }
}
Also used : MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 MetricImpl (org.sonar.ce.task.projectanalysis.metric.MetricImpl)9 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)5 Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)1 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)1 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)1 MeasureDto (org.sonar.db.measure.MeasureDto)1