Add test for delete profile field ajax page
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / utils / JsonTest.kt
1 package net.pterodactylus.sone.utils
2
3 import com.fasterxml.jackson.databind.node.ArrayNode
4 import com.fasterxml.jackson.databind.node.ObjectNode
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
7 import org.hamcrest.Matchers.instanceOf
8 import org.junit.Test
9
10 /**
11  * Unit test for JSON utilities.
12  */
13 class JsonTest {
14
15         @Test
16         fun `object node is created correctly`() {
17                 val objectNode = jsonObject {
18                         put("foo", "bar")
19                 }
20                 assertThat(objectNode, instanceOf(ObjectNode::class.java))
21                 assertThat(objectNode.toString(), equalTo("{\"foo\":\"bar\"}"))
22         }
23
24         @Test
25         fun `array node is created correctly`() {
26                 val arrayNode = listOf(
27                                 jsonObject { put("foo", "bar") },
28                                 jsonObject { put("baz", "quo") }
29                 ).toArray()
30                 assertThat(arrayNode, instanceOf(ArrayNode::class.java))
31                 assertThat(arrayNode.toString(), equalTo("[{\"foo\":\"bar\"},{\"baz\":\"quo\"}]"))
32         }
33
34         @Test
35         fun `array is created correctly for strings`() {
36             val arrayNode = jsonArray("foo", "bar", "baz")
37                 assertThat(arrayNode.toString(), equalTo("[\"foo\",\"bar\",\"baz\"]"))
38         }
39
40 }