]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Jul 2014 16:48:35 +0000 (18:48 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Jul 2014 16:54:37 +0000 (18:54 +0200)
sonar-server/src/main/java/org/sonar/server/issue/RulesAggregation.java
sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java [new file with mode: 0644]

index 433cfba56f72a7e8528b13b93ec5411187a82f06..f6f0fb7fade476be016672b6873f5cd608d0e18b 100644 (file)
@@ -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 (file)
index 0000000..31cb3fb
--- /dev/null
@@ -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);
+  }
+}