Search in sources :

Example 1 with NEW_MINOR_VIOLATIONS_KEY

use of org.sonar.api.measures.CoreMetrics.NEW_MINOR_VIOLATIONS_KEY in project sonarqube by SonarSource.

the class prMeasureFixTest method should_transform_measures.

@Test
public void should_transform_measures() {
    Set<String> requestedKeys = new HashSet<>(Arrays.asList(NEW_BUGS_KEY, MINOR_VIOLATIONS_KEY, NEW_MINOR_VIOLATIONS_KEY));
    MetricDto bugsMetric = new MetricDto().setKey(BUGS_KEY).setUuid("1");
    MetricDto newBugsMetric = new MetricDto().setKey(NEW_BUGS_KEY).setUuid("2");
    MetricDto violationsMetric = new MetricDto().setKey(MINOR_VIOLATIONS_KEY).setUuid("3");
    MetricDto newViolationsMetric = new MetricDto().setKey(NEW_MINOR_VIOLATIONS_KEY).setUuid("4");
    List<MetricDto> metricList = Arrays.asList(bugsMetric, newBugsMetric, violationsMetric, newViolationsMetric);
    LiveMeasureDto bugs = createLiveMeasure(bugsMetric.getUuid(), 10.0, null);
    LiveMeasureDto newBugs = createLiveMeasure(newBugsMetric.getUuid(), null, 5.0);
    LiveMeasureDto violations = createLiveMeasure(violationsMetric.getUuid(), 20.0, null);
    LiveMeasureDto newViolations = createLiveMeasure(newViolationsMetric.getUuid(), null, 3.0);
    Map<MetricDto, LiveMeasureDto> measureByMetric = new HashMap<>();
    measureByMetric.put(bugsMetric, bugs);
    measureByMetric.put(newBugsMetric, newBugs);
    measureByMetric.put(violationsMetric, violations);
    measureByMetric.put(newViolationsMetric, newViolations);
    PrMeasureFix.createReplacementMeasures(metricList, measureByMetric, requestedKeys);
    assertThat(measureByMetric.entrySet()).extracting(e -> e.getKey().getKey(), e -> e.getValue().getValue(), e -> e.getValue().getVariation()).containsOnly(tuple(NEW_BUGS_KEY, null, 10.0), tuple(MINOR_VIOLATIONS_KEY, 20.0, null), tuple(NEW_MINOR_VIOLATIONS_KEY, null, 20.0));
}
Also used : Arrays(java.util.Arrays) MINOR_VIOLATIONS_KEY(org.sonar.api.measures.CoreMetrics.MINOR_VIOLATIONS_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NEW_BUGS_KEY(org.sonar.api.measures.CoreMetrics.NEW_BUGS_KEY) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) MetricDto(org.sonar.db.metric.MetricDto) NEW_MINOR_VIOLATIONS_KEY(org.sonar.api.measures.CoreMetrics.NEW_MINOR_VIOLATIONS_KEY) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Map(java.util.Map) BUGS_KEY(org.sonar.api.measures.CoreMetrics.BUGS_KEY) Nullable(javax.annotation.Nullable) MetricDto(org.sonar.db.metric.MetricDto) HashMap(java.util.HashMap) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Test (org.junit.Test)1 BUGS_KEY (org.sonar.api.measures.CoreMetrics.BUGS_KEY)1 MINOR_VIOLATIONS_KEY (org.sonar.api.measures.CoreMetrics.MINOR_VIOLATIONS_KEY)1 NEW_BUGS_KEY (org.sonar.api.measures.CoreMetrics.NEW_BUGS_KEY)1 NEW_MINOR_VIOLATIONS_KEY (org.sonar.api.measures.CoreMetrics.NEW_MINOR_VIOLATIONS_KEY)1 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)1 MetricDto (org.sonar.db.metric.MetricDto)1