aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-01 18:48:35 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-01 18:54:37 +0200
commit38f6fc18ff2c25290662783fb10979a144a9d8fd (patch)
tree88a8b658959db19c2308521c2fdb776a800c0cdc /sonar-server
parent36d5431cdd2f0e2574aeba0c7d301740a8de621a (diff)
downloadsonarqube-38f6fc18ff2c25290662783fb10979a144a9d8fd.tar.gz
sonarqube-38f6fc18ff2c25290662783fb10979a144a9d8fd.zip
Fix quality flaws
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/RulesAggregation.java7
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java64
2 files changed, 65 insertions, 6 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/RulesAggregation.java b/sonar-server/src/main/java/org/sonar/server/issue/RulesAggregation.java
index 433cfba56f7..f6f0fb7fade 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/RulesAggregation.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/RulesAggregation.java
@@ -82,9 +82,6 @@ public class RulesAggregation {
Rule rule = (Rule) o;
- if (!name.equals(rule.name)) {
- return false;
- }
if (!ruleKey.equals(rule.ruleKey)) {
return false;
}
@@ -94,9 +91,7 @@ public class RulesAggregation {
@Override
public int hashCode() {
- int result = ruleKey.hashCode();
- result = 31 * result + name.hashCode();
- return result;
+ return ruleKey.hashCode();
}
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java b/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java
new file mode 100644
index 00000000000..31cb3fbc9e9
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.server.issue;
+
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.core.rule.RuleDto;
+import org.sonar.server.rule.RuleTesting;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class RulesAggregationTest {
+
+ @Test
+ public void empty() throws Exception {
+ RulesAggregation rulesAggregation = new RulesAggregation();
+ assertThat(rulesAggregation.rules()).isEmpty();
+ }
+
+ @Test
+ public void count_rules() throws Exception {
+ RulesAggregation rulesAggregation = new RulesAggregation();
+ RuleKey ruleKey = RuleKey.of("xoo", "S001");
+ RuleDto ruleDto = RuleTesting.newDto(ruleKey).setName("Rule name");
+ rulesAggregation.add(ruleDto);
+ rulesAggregation.add(ruleDto);
+
+ RulesAggregation.Rule rule = new RulesAggregation.Rule().setRuleKey(ruleKey).setName("Rule name");
+
+ assertThat(rulesAggregation.rules()).hasSize(1);
+ assertThat(rulesAggregation.rules().iterator().next().name()).isEqualTo("Rule name");
+ assertThat(rulesAggregation.countRule(rule)).isEqualTo(2);
+ }
+
+ @Test
+ public void count_rules_with_different_rules() throws Exception {
+ RulesAggregation rulesAggregation = new RulesAggregation();
+
+ RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("xoo", "S001")).setName("Rule name 1");
+ rulesAggregation.add(ruleDto);
+ rulesAggregation.add(ruleDto);
+ rulesAggregation.add(RuleTesting.newDto(RuleKey.of("xoo", "S002")).setName("Rule name 2"));
+
+ assertThat(rulesAggregation.rules()).hasSize(2);
+ }
+}