return this;
}
+ @Override
+ public int hashCode() {
+ return Boolean.valueOf(success).hashCode() ^ content.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if ((object == null) || (object.getClass() != getClass())) {
+ return false;
+ }
+ JsonReturnObject other = (JsonReturnObject) object;
+ return (success == other.success) && content.equals(other.content);
+ }
+
}
import com.fasterxml.jackson.databind.node.TextNode
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.not
import org.junit.Test
/**
}))
}
+ @Test
+ fun `successful object is not equal to unsuccessful object`() {
+ assertThat(JsonReturnObject(true), not(equalTo(JsonReturnObject(false))))
+ }
+
+ @Test
+ fun `objects with different content are not equal`() {
+ val firstObject = JsonReturnObject(true).apply {
+ put("text", "text")
+ }
+ val secondObject = JsonReturnObject(true).apply {
+ put("number", 123)
+ }
+ assertThat(firstObject, not(equalTo(secondObject)))
+ }
+
+ @Test
+ fun `object is not equal to null`() {
+ assertThat(JsonReturnObject(true), not(equalTo<Any?>(null)))
+ }
+
+ @Test
+ fun `object is not equal to object of different class`() {
+ assertThat(JsonReturnObject(true), not(equalTo<Any>("string")))
+ }
+
+ @Test
+ fun `equals is correctly implemented`() {
+ val firstObject = JsonReturnObject(true).apply {
+ put("text", "text")
+ put("int", 123)
+ put("boolean", true)
+ put("object", ObjectNode(JsonNodeFactory.instance))
+ }
+ val secondObject = JsonReturnObject(true).apply {
+ put("text", "text")
+ put("int", 123)
+ put("boolean", true)
+ put("object", ObjectNode(JsonNodeFactory.instance))
+ }
+ assertThat(firstObject, equalTo(secondObject))
+ }
+
+ @Test
+ fun `hash code of equal objects is equal`() {
+ val firstObject = JsonReturnObject(true).apply {
+ put("text", "text")
+ put("int", 123)
+ put("boolean", true)
+ put("object", ObjectNode(JsonNodeFactory.instance))
+ }
+ val secondObject = JsonReturnObject(true).apply {
+ put("text", "text")
+ put("int", 123)
+ put("boolean", true)
+ put("object", ObjectNode(JsonNodeFactory.instance))
+ }
+ assertThat(firstObject.hashCode(), equalTo(secondObject.hashCode()))
+ }
+
}