X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonReturnObjectTest.kt;h=784913941c860405f017ea212e6873b6b58a7972;hb=ae78f11f111ddc964a36cc25ab6da413685d69a6;hp=4acb8aa8f4e06d5247b84f33d5873ce40588b569;hpb=2a58b5e97b774664376de1d6a676aa0f38d30b18;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonReturnObjectTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonReturnObjectTest.kt index 4acb8aa..7849139 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonReturnObjectTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonReturnObjectTest.kt @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode 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 /** @@ -83,8 +84,68 @@ class JsonReturnObjectTest { put("text", "text") put("int", 123) put("boolean", true) - put("object", objectNode) + set("object", objectNode) })) } + @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(null))) + } + + @Test + fun `object is not equal to object of different class`() { + assertThat(JsonReturnObject(true), not(equalTo("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())) + } + }