aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl/src/test/java
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-03-11 17:04:42 -0600
committersonartech <sonartech@sonarsource.com>2021-03-17 20:08:34 +0000
commit398550aef256c12cd680795699890038af2dbf8d (patch)
treea0043bb86c3a3bfcf9357e8d5dbdb3ac68fd5859 /sonar-plugin-api-impl/src/test/java
parent4e76eae61a9cc708dde1e71d1895dfbb810f63ce (diff)
downloadsonarqube-398550aef256c12cd680795699890038af2dbf8d.tar.gz
sonarqube-398550aef256c12cd680795699890038af2dbf8d.zip
SONAR-14192 Deprecating rule keys may break users' exclusion settings
Diffstat (limited to 'sonar-plugin-api-impl/src/test/java')
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/rule/internal/DefaultActiveRulesTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/rule/internal/DefaultActiveRulesTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/rule/internal/DefaultActiveRulesTest.java
new file mode 100644
index 00000000000..32a60c6c8b8
--- /dev/null
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/rule/internal/DefaultActiveRulesTest.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.rule.internal;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.WildcardPattern;
+
+import static java.util.Collections.singleton;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultActiveRulesTest {
+ private final RuleKey ruleKey = RuleKey.of("repo", "rule");
+
+ @Test
+ public void empty_returns_nothing() {
+ DefaultActiveRules underTest = new DefaultActiveRules(Collections.emptyList());
+
+ assertThat(underTest.getDeprecatedRuleKeys(ruleKey)).isEmpty();
+ assertThat(underTest.matchesDeprecatedKeys(ruleKey, WildcardPattern.create("**"))).isFalse();
+ }
+
+ @Test
+ public void finds_match() {
+ DefaultActiveRules underTest = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder()
+ .setRuleKey(ruleKey)
+ .setDeprecatedKeys(singleton(RuleKey.of("oldrepo", "oldrule")))
+ .build()));
+
+ assertThat(underTest.getDeprecatedRuleKeys(ruleKey)).containsOnly("oldrepo:oldrule");
+ assertThat(underTest.matchesDeprecatedKeys(ruleKey, WildcardPattern.create("oldrepo:oldrule"))).isTrue();
+ }
+
+ @Test
+ public void finds_match_with_multiple_deprecated_keys() {
+ DefaultActiveRules underTest = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder()
+ .setRuleKey(ruleKey)
+ .setDeprecatedKeys(ImmutableSet.of(RuleKey.of("oldrepo", "oldrule"), (RuleKey.of("oldrepo2", "oldrule2"))))
+ .build()));
+
+ assertThat(underTest.getDeprecatedRuleKeys(ruleKey)).containsOnly("oldrepo:oldrule", "oldrepo2:oldrule2");
+ assertThat(underTest.matchesDeprecatedKeys(ruleKey, WildcardPattern.create("oldrepo:oldrule"))).isTrue();
+ }
+}