Skip to content

Commit 2b31886

Browse files
author
Michael Kunze
committed
Restore equals and hashcode on MetricKeyPair
That is being used by tests if you want to make sure that the dao is being called with the correct number of parameters.
1 parent 0cc611b commit 2b31886

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group = "de.inoxio"
15-
version = "1.0.0"
15+
version = "1.0.1"
1616
description = "A java-spring library to push metrics to cloudwatch"
1717

1818
apply {
@@ -32,6 +32,7 @@ dependencies {
3232
// test
3333
testImplementation("org.springframework.boot:spring-boot-starter-test")
3434
testImplementation("org.mockito:mockito-core:2.23.0")
35+
testImplementation("nl.jqno.equalsverifier:equalsverifier:3.0")
3536
}
3637

3738
java {

src/main/java/de/inoxio/spring/cloudwatchmetrics/MetricKeyPair.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package de.inoxio.spring.cloudwatchmetrics;
22

3-
public class MetricKeyPair {
3+
import java.util.Objects;
4+
5+
public final class MetricKeyPair {
46

57
private final String name;
68
private final double value;
@@ -18,6 +20,30 @@ public double getValue() {
1820
return value;
1921
}
2022

23+
@Override
24+
public boolean equals(final Object o) {
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
31+
32+
final var that = (MetricKeyPair) o;
33+
34+
return Double.compare(that.value, value) == 0 && Objects.equals(name, that.name);
35+
}
36+
37+
@Override
38+
public int hashCode() {
39+
return Objects.hash(name, value);
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return "MetricKeyPair{" + "name='" + name + '\'' + ", value=" + value + '}';
45+
}
46+
2147
public static final class MetricKeyPairBuilder {
2248

2349
private String name;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.inoxio.spring.cloudwatchmetrics;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.is;
5+
6+
import static de.inoxio.spring.cloudwatchmetrics.MetricKeyPair.MetricKeyPairBuilder.metricKeyPairBuilder;
7+
8+
import org.junit.Test;
9+
10+
import nl.jqno.equalsverifier.EqualsVerifier;
11+
12+
public class MetricKeyPairTest {
13+
14+
@Test
15+
public void shouldTestEqualsAndHashcode() {
16+
EqualsVerifier.forClass(MetricKeyPair.class).verify();
17+
}
18+
19+
@Test
20+
public void shouldConvertObjectToString() {
21+
22+
// given
23+
final var metricKeyPair = metricKeyPairBuilder().name("name").value(1.0).build();
24+
25+
// when
26+
final var toString = metricKeyPair.toString();
27+
28+
// then
29+
assertThat(toString, is("MetricKeyPair{name='name', value=1.0}"));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)