X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetTimesAjaxPageTest.kt;h=d6b5aa065a3da765ec3d91a62747e0ce89f2ae07;hp=5bffe094e78518aaa74c6eba613747aaad64c93a;hb=889119651988ace06a94568a661f29b87f1af99e;hpb=f339996e95e45359e14becbe62d49863cf26acfd diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt index 5bffe09..d6b5aa0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt @@ -14,7 +14,6 @@ import net.pterodactylus.sone.utils.jsonObject import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsInAnyOrder import org.hamcrest.Matchers.emptyIterable -import org.hamcrest.Matchers.equalTo import org.junit.Before import org.junit.Test import org.mockito.ArgumentMatchers.any @@ -54,29 +53,29 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f @Test fun `request without any parameters responds with empty post and reply times`() { - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["postTimes"].toList(), emptyIterable()) - assertThat(json["replyTimes"].toList(), emptyIterable()) + assertThatJsonIsSuccessful() + assertThat(json["postTimes"]?.toList(), emptyIterable()) + assertThat(json["replyTimes"]?.toList(), emptyIterable()) } @Test fun `request with single post parameter responds with post times and empty reply times`() { addPost(testPosts[0]) addRequestParameter("posts", "post1") - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["postTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( + assertThatJsonIsSuccessful() + assertThat(json["postTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( "post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01") )) - assertThat(json["replyTimes"].toList(), emptyIterable()) + assertThat(json["replyTimes"]?.toList(), emptyIterable()) } @Test fun `request with single reply parameter responds with reply times and empty post times`() { addReply(testReplies[0]) addRequestParameter("replies", "reply1") - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["postTimes"].toList(), emptyIterable()) - assertThat(json["replyTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( + assertThatJsonIsSuccessful() + assertThat(json["postTimes"]?.toList(), emptyIterable()) + assertThat(json["replyTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( "reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01") )) } @@ -86,12 +85,12 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f addPost(testPosts[0]) addPost(testPosts[1]) addRequestParameter("posts", "post1,post2,post3") - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["postTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( + assertThatJsonIsSuccessful() + assertThat(json["postTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( "post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01"), "post2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 00:00:02") )) - assertThat(json["replyTimes"].toList(), emptyIterable()) + assertThat(json["replyTimes"]?.toList(), emptyIterable()) } @Test @@ -99,9 +98,9 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f addReply(testReplies[0]) addReply(testReplies[1]) addRequestParameter("replies", "reply1,reply2,reply3") - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["postTimes"].toList(), emptyIterable()) - assertThat(json["replyTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( + assertThatJsonIsSuccessful() + assertThat(json["postTimes"]?.toList(), emptyIterable()) + assertThat(json["replyTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder>( "reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01"), "reply2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 00:00:02") ))