From: Sébastien Lesaint Date: Wed, 14 Aug 2019 07:49:42 +0000 (+0200) Subject: fix bad UT in RegisterMetricsTest X-Git-Tag: 8.0~245 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=717ca84b9bfde7d50a20f13e3a45ab032546c7e6;p=sonarqube.git fix bad UT in RegisterMetricsTest which caused it to be unstable --- diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java index 93ab824d8c7..b5fc51496cd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java @@ -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);