X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FJsonTest.kt;h=9c68e622529a6f5b6e763bdfdf5313a7f7af04d9;hb=2a202f56661ecbfb1be46066a1df7c4dad3042e3;hp=ff741c1df45f01e52e2bcb7fd9205a3b0a6dd6f1;hpb=ccc17ddce331a6c70e3e6a14df34ca73c05ed012;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/utils/JsonTest.kt b/src/test/kotlin/net/pterodactylus/sone/utils/JsonTest.kt index ff741c1..9c68e62 100644 --- a/src/test/kotlin/net/pterodactylus/sone/utils/JsonTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/utils/JsonTest.kt @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.instanceOf +import org.hamcrest.Matchers.nullValue import org.junit.Test /** @@ -22,6 +23,20 @@ class JsonTest { } @Test + fun `object node is created with correctly-typed properties`() { + val objectNode = jsonObject("string" to "foo", "int" to 1, "long" to 2L, "boolean" to true, "other" to Any()) + assertThat(objectNode["string"].isTextual, equalTo(true)) + assertThat(objectNode["string"].asText(), equalTo("foo")) + assertThat(objectNode["int"].isInt, equalTo(true)) + assertThat(objectNode["int"].asInt(), equalTo(1)) + assertThat(objectNode["long"].isLong, equalTo(true)) + assertThat(objectNode["long"].asLong(), equalTo(2L)) + assertThat(objectNode["boolean"].isBoolean, equalTo(true)) + assertThat(objectNode["boolean"].asBoolean(), equalTo(true)) + assertThat(objectNode["other"], nullValue()) + } + + @Test fun `array node is created correctly`() { val arrayNode = listOf( jsonObject { put("foo", "bar") }, @@ -31,4 +46,10 @@ class JsonTest { assertThat(arrayNode.toString(), equalTo("[{\"foo\":\"bar\"},{\"baz\":\"quo\"}]")) } + @Test + fun `array is created correctly for strings`() { + val arrayNode = jsonArray("foo", "bar", "baz") + assertThat(arrayNode.toString(), equalTo("[\"foo\",\"bar\",\"baz\"]")) + } + }