]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11376 Add UT for LiveMeasureDao
authorBenoît Gianinetti <benoit.gianinetti@sonarsource.com>
Wed, 24 Oct 2018 14:43:37 +0000 (16:43 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 7 Nov 2018 19:21:03 +0000 (20:21 +0100)
server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java

index 291ff72290f65dc5c6e367162659dbef92dc65a4..f1d3cb709955b3a73dca1f26cf51b617c64df6cf 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import org.apache.commons.lang.RandomStringUtils;
+import java.util.Optional;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -139,6 +140,33 @@ public class LiveMeasureDaoTest {
     assertThat(selected).isEmpty();
   }
 
+  @Test
+  public void selectByComponentUuidAndMetricKey() {
+    LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+    underTest.insert(db.getSession(), measure);
+
+    Optional<LiveMeasureDto> selected = underTest.selectByComponentUuidAndMetricKey(db.getSession(), measure.getComponentUuid(), metric.getKey());
+
+    assertThat(selected).isNotEmpty();
+    assertThat(selected.get()).isEqualToComparingFieldByField(measure);
+  }
+
+  @Test
+  public void selectByComponentUuidAndMetricKey_return_empty_if_component_does_not_match() {
+    LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+    underTest.insert(db.getSession(), measure);
+
+    assertThat(underTest.selectByComponentUuidAndMetricKey(db.getSession(), "_missing_", metric.getKey())).isEmpty();
+  }
+
+  @Test
+  public void selectByComponentUuidAndMetricKey_return_empty_if_metric_does_not_match() {
+    LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+    underTest.insert(db.getSession(), measure);
+
+    assertThat(underTest.selectByComponentUuidAndMetricKey(db.getSession(), measure.getComponentUuid(), "_missing_")).isEmpty();
+  }
+
   @Test
   public void selectMeasure() {
     MetricDto metric = db.measures().insertMetric();