Skip to content

Commit 5b191fb

Browse files
author
Michael Kunze
committed
Add equals and hascode to DimensionKeyPair as well
Once again this is needed for proper testing
1 parent 2b31886 commit 5b191fb

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

build.gradle.kts

Lines changed: 1 addition & 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.1"
15+
version = "1.0.2"
1616
description = "A java-spring library to push metrics to cloudwatch"
1717

1818
apply {

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package de.inoxio.spring.cloudwatchmetrics;
22

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

57
private final String name;
68
private final String value;
79

8-
public DimensionKeyPair(final String name, final String value) {
10+
private DimensionKeyPair(final String name, final String value) {
911
this.name = name;
1012
this.value = value;
1113
}
@@ -18,6 +20,30 @@ public String 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 = (DimensionKeyPair) o;
33+
34+
return Objects.equals(name, that.name) && Objects.equals(value, that.value);
35+
}
36+
37+
@Override
38+
public int hashCode() {
39+
return Objects.hash(name, value);
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return "DimensionKeyPair{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
45+
}
46+
2147
public static final class DimensionKeyPairBuilder {
2248

2349
private String name;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public final class MetricKeyPair {
77
private final String name;
88
private final double value;
99

10-
public MetricKeyPair(final String name, final double value) {
10+
private MetricKeyPair(final String name, final double value) {
1111
this.name = name;
1212
this.value = value;
1313
}
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.DimensionKeyPair.DimensionKeyPairBuilder.dimensionKeyPairBuilder;
7+
8+
import org.junit.Test;
9+
10+
import nl.jqno.equalsverifier.EqualsVerifier;
11+
12+
public class DimensionKeyPairTest {
13+
14+
@Test
15+
public void shouldTestEqualsAndHashcode() {
16+
EqualsVerifier.forClass(DimensionKeyPair.class).verify();
17+
}
18+
19+
@Test
20+
public void shouldConvertObjectToString() {
21+
22+
// given
23+
final var dimensionKeyPair = dimensionKeyPairBuilder().name("name").value("value").build();
24+
25+
// when
26+
final var toString = dimensionKeyPair.toString();
27+
28+
// then
29+
assertThat(toString, is("DimensionKeyPair{name='name', value='value'}"));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)