]> source.dussan.org Git - sonarqube.git/commitdiff
fix bad UT in RegisterMetricsTest
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 14 Aug 2019 07:49:42 +0000 (09:49 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 14 Aug 2019 18:21:11 +0000 (20:21 +0200)
which caused it to be unstable

server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java

index 93ab824d8c7b80bac4f7c9a0454ebb0fea1238ad..b5fc51496cd9816cc5e69db09d0417f32596527b 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.db.metric.MetricDto;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 
 public class RegisterMetricsTest {
@@ -146,8 +147,8 @@ public class RegisterMetricsTest {
 
   @Test
   public void enable_disabled_metrics() {
-    MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true));
-    MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false));
+    MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(false));
+    MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(false));
 
     RegisterMetrics register = new RegisterMetrics(dbClient);
     register.register(asList(builderOf(enabledMetric).create(), builderOf(disabledMetric).create()));
@@ -157,6 +158,21 @@ public class RegisterMetricsTest {
       .containsOnly(true, true);
   }
 
+  @Test
+  public void does_not_enable_disabled_custom_metrics() {
+    MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(true));
+    MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(true));
+
+    RegisterMetrics register = new RegisterMetrics(dbClient);
+    register.register(asList(builderOf(enabledMetric).create(), builderOf(disabledMetric).create()));
+
+    assertThat(selectAllMetrics().values())
+      .extracting(MetricDto::getKey, MetricDto::isEnabled)
+      .containsOnly(
+        tuple(enabledMetric.getKey(), true),
+        tuple(disabledMetric.getKey(), false));
+  }
+
   @Test
   public void insert_core_metrics() {
     RegisterMetrics register = new RegisterMetrics(dbClient);