diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-01 22:55:24 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-01 22:58:36 +0200 |
commit | 6c0da1115cd26a1e41195c3924d94d46dda0e38b (patch) | |
tree | 0f6c937f130d7df7dfe9094df636bf09c23bf644 /sonar-core | |
parent | 09b33b23a4d08ba107572c8b2e8ca30302e41db1 (diff) | |
download | sonarqube-6c0da1115cd26a1e41195c3924d94d46dda0e38b.tar.gz sonarqube-6c0da1115cd26a1e41195c3924d94d46dda0e38b.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java | 3 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java | 61 |
2 files changed, 64 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java index 8e730d517ef..8c3de2f29c6 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java @@ -49,6 +49,9 @@ public class ActiveRuleDto extends Dto<ActiveRuleKey> { private Integer severity; private String inheritance; + /** + * for internal use, should be private + */ @Deprecated public ActiveRuleDto setKey(ActiveRuleKey key) { this.repository = key.ruleKey().repository(); diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java new file mode 100644 index 00000000000..10026049cca --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java @@ -0,0 +1,61 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.core.qualityprofile.db; + +import org.junit.Test; +import org.sonar.api.rule.RuleKey; + +import static org.fest.assertions.Assertions.assertThat; + +public class ActiveRuleKeyTest { + + @Test + public void of() throws Exception { + RuleKey ruleKey = RuleKey.of("xoo", "R1"); + ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey); + assertThat(key.qProfile()).isEqualTo("P1"); + assertThat(key.ruleKey()).isSameAs(ruleKey); + assertThat(key.toString()).isEqualTo("P1:xoo:R1"); + } + + @Test + public void parse() throws Exception { + ActiveRuleKey key = ActiveRuleKey.parse("P1:xoo:R1"); + assertThat(key.qProfile()).isEqualTo("P1"); + assertThat(key.ruleKey().repository()).isEqualTo("xoo"); + assertThat(key.ruleKey().rule()).isEqualTo("R1"); + } + + @Test + public void equals_and_hashcode() throws Exception { + ActiveRuleKey key1 = ActiveRuleKey.parse("P1:xoo:R1"); + ActiveRuleKey key1b = ActiveRuleKey.parse("P1:xoo:R1"); + ActiveRuleKey key2 = ActiveRuleKey.parse("P1:xoo:R2"); + ActiveRuleKey key3 = ActiveRuleKey.parse("P2:xoo:R1"); + assertThat(key1.equals(key1)).isTrue(); + assertThat(key1.equals(key1b)).isTrue(); + assertThat(key1.equals(null)).isFalse(); + assertThat(key1.equals("P1:xoo:R1")).isFalse(); + assertThat(key1.equals(key2)).isFalse(); + assertThat(key1.equals(key3)).isFalse(); + + assertThat(key1.hashCode()).isEqualTo(key1.hashCode()); + } +} |