This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 7f0665081ba4e63a3989c37334ee3fad47113970 Author: Tran Tien Duc <[email protected]> AuthorDate: Thu Dec 12 15:47:30 2019 +0700 JAMES-3007 HealthCheck components equals, hashCode --- .../james/core/healthcheck/ComponentName.java | 26 +++++++++++++++++++ .../org/apache/james/core/healthcheck/Result.java | 29 ++++++++++++++++++++++ .../james/core/healthcheck/ComponentNameTest.java} | 17 +++++++------ .../apache/james/core/healthcheck/ResultTest.java | 8 ++++++ 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java b/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java index ecb248a..0707c0e 100644 --- a/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java +++ b/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java @@ -19,6 +19,10 @@ package org.apache.james.core.healthcheck; +import java.util.Objects; + +import com.google.common.base.MoreObjects; + public class ComponentName { private final String name; @@ -29,4 +33,26 @@ public class ComponentName { public String getName() { return name; } + + @Override + public final boolean equals(Object o) { + if (o instanceof ComponentName) { + ComponentName that = (ComponentName) o; + + return Objects.equals(this.name, that.name); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(name); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("name", name) + .toString(); + } } diff --git a/core/src/main/java/org/apache/james/core/healthcheck/Result.java b/core/src/main/java/org/apache/james/core/healthcheck/Result.java index e204069..6345cda 100644 --- a/core/src/main/java/org/apache/james/core/healthcheck/Result.java +++ b/core/src/main/java/org/apache/james/core/healthcheck/Result.java @@ -18,8 +18,11 @@ ****************************************************************/ package org.apache.james.core.healthcheck; +import java.util.Objects; import java.util.Optional; +import com.google.common.base.MoreObjects; + public class Result { public static Result healthy(ComponentName componentName) { @@ -67,4 +70,30 @@ public class Result { public Optional<String> getCause() { return cause; } + + @Override + public final boolean equals(Object o) { + if (o instanceof Result) { + Result result = (Result) o; + + return Objects.equals(this.componentName, result.componentName) + && Objects.equals(this.status, result.status) + && Objects.equals(this.cause, result.cause); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(componentName, status, cause); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("componentName", componentName) + .add("status", status) + .add("cause", cause) + .toString(); + } } \ No newline at end of file diff --git a/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java b/core/src/test/java/org/apache/james/core/healthcheck/ComponentNameTest.java similarity index 84% copy from core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java copy to core/src/test/java/org/apache/james/core/healthcheck/ComponentNameTest.java index ecb248a..08f708d 100644 --- a/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java +++ b/core/src/test/java/org/apache/james/core/healthcheck/ComponentNameTest.java @@ -19,14 +19,15 @@ package org.apache.james.core.healthcheck; -public class ComponentName { - private final String name; +import org.junit.jupiter.api.Test; - public ComponentName(String name) { - this.name = name; - } +import nl.jqno.equalsverifier.EqualsVerifier; + +class ComponentNameTest { - public String getName() { - return name; + @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(ComponentName.class) + .verify(); } -} +} \ No newline at end of file diff --git a/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java b/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java index e2e96fe..e504ccd 100644 --- a/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java +++ b/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java @@ -23,11 +23,19 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.Test; +import nl.jqno.equalsverifier.EqualsVerifier; + class ResultTest { private static final ComponentName COMPONENT_NAME = new ComponentName("component"); @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(Result.class) + .verify(); + } + + @Test void componentNameShouldBeKeptWhenHealthy() { Result result = Result.healthy(COMPONENT_NAME); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
