From 21d65415b3b95325dfe81a0ba48c4a43670eff11 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 26 Feb 2014 14:00:28 +0100 Subject: SONAR-5067 Fail when activating already activated rules on a profile --- .../org/sonar/api/profiles/RulesProfileTest.java | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'sonar-plugin-api/src/test/java/org/sonar') 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')"); + } } } -- cgit v1.2.3