aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-10 11:00:09 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-11 10:28:35 +0200
commit97a4b69e4653d0db1040705738ab8269bb907da2 (patch)
tree4f2c72f459243445ea35569c8d9c14f7cf9f3cd6
parentccc92bfab6287510eb5d77d2b5f904be4feffd01 (diff)
downloadsonarqube-97a4b69e4653d0db1040705738ab8269bb907da2.tar.gz
sonarqube-97a4b69e4653d0db1040705738ab8269bb907da2.zip
SONAR-6620 Metric's equals/hashcode should use only the key
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/metric/MetricImpl.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricImplTest.java12
2 files changed, 6 insertions, 11 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/metric/MetricImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/metric/MetricImpl.java
index 58153bfe8bf..ea593168e16 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/metric/MetricImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/metric/MetricImpl.java
@@ -62,13 +62,12 @@ public final class MetricImpl implements Metric {
return false;
}
MetricImpl metric = (MetricImpl) o;
- return Objects.equals(key, metric.key) &&
- Objects.equals(type, metric.type);
+ return Objects.equals(key, metric.key);
}
@Override
public int hashCode() {
- return Objects.hash(key, type);
+ return key.hashCode();
}
@Override
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricImplTest.java
index 7e7de32a34f..eeba504f15e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricImplTest.java
@@ -53,24 +53,20 @@ public class MetricImplTest {
}
@Test
- public void equals_uses_key_and_name() {
+ public void equals_uses_only_key() {
MetricImpl expected = new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
assertThat(new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.STRING)).isEqualTo(expected);
assertThat(new MetricImpl("some other key", SOME_NAME, Metric.MetricType.FLOAT)).isNotEqualTo(expected);
- assertThat(new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.STRING)).isNotEqualTo(expected);
}
@Test
- public void equals_ignores_valueType() {
- assertThat(new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT)).isEqualTo(new MetricImpl(SOME_KEY, "some other name", Metric.MetricType.FLOAT));
- }
-
- @Test
- public void hashcode_uses_only_key_and_valueType() {
+ public void hashcode_uses_only_key() {
int expected = new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).hashCode();
assertThat(new MetricImpl(SOME_KEY, "some other name", Metric.MetricType.FLOAT).hashCode()).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_KEY, "some other name", Metric.MetricType.BOOL).hashCode()).isEqualTo(expected);
}
@Test