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=fff438bdf04107bd6ecdf9512b68d49b7d55f698;hp=585316d4ca0b286fc59613d806a12803d6a9a308;hb=43278c5468221baa16946a5206c3a4e97d543010;hpb=d91e48af542fef4c0064c5a6641b473240ef4273 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 585316d..fff438b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt @@ -19,6 +19,7 @@ import org.junit.Before import org.junit.Test import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyLong +import java.util.TimeZone.getTimeZone /** * Unit test for [GetTimesAjaxPage]. @@ -27,9 +28,9 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f private val timeTextConverter = mock() private val l10nFilter = mock() - override val page: JsonPage by lazy { GetTimesAjaxPage(webInterface, timeTextConverter, l10nFilter) } - private val posts = listOf(createPost(1), createPost(2)) - private val replies = listOf(createReply(1), createReply(2)) + override val page: JsonPage by lazy { GetTimesAjaxPage(webInterface, timeTextConverter, l10nFilter, getTimeZone("UTC")) } + private val testPosts = listOf(createPost(1), createPost(2)) + private val testReplies = listOf(createReply(1), createReply(2)) private fun createPost(index: Int): Post { return mock().apply { @@ -53,56 +54,56 @@ 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(posts[0]) + addPost(testPosts[0]) addRequestParameter("posts", "post1") - assertThat(json.isSuccess, equalTo(true)) - 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, 01:00:01") + 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(replies[0]) + 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>( - "reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 01:00:01") + 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") )) } @Test fun `request with multiple post parameter responds with post times and empty reply times`() { - addPost(posts[0]) - addPost(posts[1]) + 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>( - "post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 01:00:01"), - "post2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 01:00:02") + 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 fun `request with multiple reply parameters responds with reply times and empty post times`() { - addReply(replies[0]) - addReply(replies[1]) + 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>( - "reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 01:00:01"), - "reply2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 01:00:02") + 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") )) }