aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-26 14:00:28 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-26 14:01:40 +0100
commit21d65415b3b95325dfe81a0ba48c4a43670eff11 (patch)
treea149452367d56b7c8e59a2f855c3daf3e7676004 /sonar-plugin-api/src/test
parent40f8b2e97602948cec51fb7c21f2c261c85e9a68 (diff)
downloadsonarqube-21d65415b3b95325dfe81a0ba48c4a43670eff11.tar.gz
sonarqube-21d65415b3b95325dfe81a0ba48c4a43670eff11.zip
SONAR-5067 Fail when activating already activated rules on a profile
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java32
1 files changed, 23 insertions, 9 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java
index c59a5f57ccb..3a31a73b060 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java
@@ -23,9 +23,9 @@ import org.junit.Test;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
public class RulesProfileTest {
@@ -35,8 +35,8 @@ public class RulesProfileTest {
profile.activateRule(Rule.create("repo", "key1", "name1"), null);
profile.activateRule(Rule.create("repo", "key2", "name2").setConfigKey("config2"), null);
- assertNull(profile.getActiveRuleByConfigKey("repo", "unknown"));
- assertThat(profile.getActiveRuleByConfigKey("repo", "config2").getRuleKey(), is("key2"));
+ assertThat(profile.getActiveRuleByConfigKey("repo", "unknown")).isNull();
+ assertThat(profile.getActiveRuleByConfigKey("repo", "config2").getRuleKey()).isEqualTo("key2");
}
@Test
@@ -44,7 +44,7 @@ public class RulesProfileTest {
RulesProfile profile = RulesProfile.create();
Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, null);
- assertThat(profile.getActiveRule("repo", "key1").getSeverity(), is(RulePriority.CRITICAL));
+ assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.CRITICAL);
}
@Test
@@ -52,12 +52,26 @@ public class RulesProfileTest {
RulesProfile profile = RulesProfile.create();
Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, RulePriority.MINOR);
- assertThat(profile.getActiveRule("repo", "key1").getSeverity(), is(RulePriority.MINOR));
+ assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR);
}
@Test
public void defaultVersionIs1() {
- RulesProfile profile = RulesProfile.create();
- assertThat(profile.getVersion(), is(1));
+ RulesProfile profile = RulesProfile.create();
+ assertThat(profile.getVersion()).isEqualTo(1);
+ }
+
+ @Test
+ public void fail_to_activate_already_activated_rule() {
+ RulesProfile profile = RulesProfile.create("Default", "java");
+ Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
+ profile.activateRule(rule, null);
+
+ try {
+ profile.activateRule(rule, null);
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("The rule 'repo:key1' is already activated on the profile 'Default' (language 'java')");
+ }
}
}