X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetStatusAjaxPageTest.kt;h=9576c7c46116512ef73da07fec876b7142f5cbfa;hp=0d8cb543639a1487a86f309a5e27224f9cd9a259;hb=d58ef344b43543fdcfca13c07df87e194f004376;hpb=959d2b0a4c4636c73d531d1097f062bf5f8e3edf diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPageTest.kt index 0d8cb54..9576c7c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPageTest.kt @@ -42,18 +42,18 @@ class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = fals @Test fun `page returns correct attribute “loggedIn” if sone is logged in`() { - assertThat(json.get("loggedIn").asText(), equalTo("true")) + assertThat(json.get("loggedIn")?.asText(), equalTo("true")) } @Test fun `page returns correct attribute “loggedIn” if sone is not logged in`() { unsetCurrentSone() - assertThat(json.get("loggedIn").asText(), equalTo("false")) + assertThat(json.get("loggedIn")?.asText(), equalTo("false")) } @Test fun `page returns options for sone if sone is logged in`() { - assertThat(json.get("options").toMap(), allOf( + assertThat(json.get("options")?.toMap(), allOf( hasEntry("ShowNotification/NewSones", "true"), hasEntry("ShowNotification/NewPosts", "true"), hasEntry("ShowNotification/NewReplies", "true") @@ -74,7 +74,7 @@ class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = fals @Test fun `page returns a sones object with the current sone if not other sones parameter is given`() { - assertThat(json.get("sones").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( + assertThat(json.get("sones")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( mapOf("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:01", "lastUpdatedText" to "1000") )) } @@ -84,7 +84,7 @@ class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = fals addSone(deepMock().mock("sone1", "Sone 1", false, 2000, downloading)) addSone(deepMock().mock("sone3", "Sone 3", true, 3000, inserting)) addRequestParameter("soneIds", "sone1,sone2,sone3") - assertThat(json.get("sones").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( + assertThat(json.get("sones")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( mapOf("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:01", "lastUpdatedText" to "1000"), mapOf("id" to "sone1", "name" to "Sone 1", "local" to "false", "status" to "downloading", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:02", "lastUpdatedText" to "2000"), mapOf("id" to "sone3", "name" to "Sone 3", "local" to "true", "status" to "inserting", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:03", "lastUpdatedText" to "3000") @@ -98,14 +98,14 @@ class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = fals mock().apply { whenever(this.createdTime).thenReturn(1000) } ) notifications.forEachIndexed { index, notification -> addNotification(notification, "notification$index")} - assertThat(json.get("notificationHash").asInt(), equalTo(notifications.sortedBy { it.createdTime }.hashCode())) + assertThat(json.get("notificationHash")?.asInt(), equalTo(notifications.sortedBy { it.createdTime }.hashCode())) } @Test fun `page returns new posts`() { addNewPost("post1", "sone1", 1000) addNewPost("post2", "sone2", 2000, "sone1") - assertThat(json.get("newPosts").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( + assertThat(json.get("newPosts")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( mapOf("id" to "post1", "sone" to "sone1", "time" to "1000", "recipient" to null), mapOf("id" to "post2", "sone" to "sone2", "time" to "2000", "recipient" to "sone1") )) @@ -115,7 +115,7 @@ class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = fals fun `page returns new replies`() { addNewReply("reply1", "sone1", "post1", "sone11") addNewReply("reply2", "sone2", "post2", "sone22") - assertThat(json.get("newReplies").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( + assertThat(json.get("newReplies")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( mapOf("id" to "reply1", "sone" to "sone1", "post" to "post1", "postSone" to "sone11"), mapOf("id" to "reply2", "sone" to "sone2", "post" to "post2", "postSone" to "sone22") )) @@ -127,7 +127,7 @@ class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = fals addLinkedElement("KSK@test.html", loading = true, failed = false) addLinkedElement("KSK@test.jpeg", loading = false, failed = true) addRequestParameter("elements", jsonArray("KSK@test.png", "KSK@test.html", "KSK@test.jpeg").toString()) - assertThat(json.get("linkedElements").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( + assertThat(json.get("linkedElements")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder( mapOf("link" to "KSK@test.png", "loading" to "false", "failed" to "false"), mapOf("link" to "KSK@test.html", "loading" to "true", "failed" to "false"), mapOf("link" to "KSK@test.jpeg", "loading" to "false", "failed" to "true")