From: David ‘Bombe’ Roden Date: Fri, 13 Jan 2017 18:11:05 +0000 (+0100) Subject: Use methods from test base class X-Git-Tag: 0.9.7^2~344 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;ds=sidebyside;h=cb42023e00a28dd58bffc7eb3b753adf3ab20f29;hp=290f54ab871fd8267cdecab78cffd0f79cedd39a;p=Sone.git Use methods from test base class --- diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt index dff812b..e830daf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt @@ -2,8 +2,6 @@ package net.pterodactylus.sone.fcp import freenet.support.SimpleFieldSet import net.pterodactylus.sone.core.Core -import net.pterodactylus.sone.data.Post -import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.test.asOptional import net.pterodactylus.sone.test.mock @@ -23,20 +21,19 @@ class GetPostCommandTest : SoneCommandTest() { private val sone = mock().apply { whenever(id).thenReturn("SoneId") } - private val post = createPost() + private val post = createPost("ValidPostId", sone, null, 1000, "Post Text\r\nSecond \\Line") + private val sone1 = mock().apply { whenever(id).thenReturn("Sone1") } + private val sone2 = mock().apply { whenever(id).thenReturn("Sone2") } + private val postReply1 = createReply("ReplyId1", sone1, post, 1000, "Reply 1") + private val postReply2 = createReply("ReplyId2", sone2, post, 2000, "Reply 2") override fun createCommand(core: Core) = GetPostCommand(core) @Before fun setupPostWithLikesAndReplies() { whenever(core.getPost("ValidPostId")).thenReturn(post.asOptional()) - val sone1 = mock().apply { whenever(id).thenReturn("Sone1") } - val sone2 = mock().apply { whenever(id).thenReturn("Sone2") } whenever(core.getLikes(post)).thenReturn(setOf(sone1, sone2)) - val replies = listOf( - createPostReply("ReplyId1", sone1, 1000, "Reply 1"), - createPostReply("ReplyId2", sone2, 2000, "Reply 2") - ) + val replies = listOf(postReply1, postReply2) whenever(core.getReplies("ValidPostId")).thenReturn(replies) } @@ -56,41 +53,17 @@ class GetPostCommandTest : SoneCommandTest() { executeCommandAndExpectFcpException() } - private fun createPostReply(id: String, sone: Sone, time: Long, text: String) = mock().apply { - whenever(this.id).thenReturn(id) - whenever(this.sone).thenReturn(sone) - whenever(this.time).thenReturn(time) - whenever(this.text).thenReturn(text) - } - - private fun createPost() = mock().apply { - whenever(id).thenReturn("ValidPostId") - whenever(this.sone).thenReturn(this@GetPostCommandTest.sone) - whenever(recipientId).thenReturn(null.asOptional()) - whenever(time).thenReturn(1000) - whenever(text).thenReturn("Post Text\r\nSecond \\Line") - } - private fun verifyPostWithLikes(replyParameters: SimpleFieldSet) { assertThat(replyParameters["Message"], equalTo("Post")) - assertThat(replyParameters["Post.ID"], equalTo("ValidPostId")) - assertThat(replyParameters["Post.Sone"], equalTo("SoneId")) - assertThat(replyParameters["Post.Time"], equalTo("1000")) - assertThat(replyParameters["Post.Text"], equalTo("Post Text\\r\\nSecond \\\\Line")) + assertThat(replyParameters.parsePost("Post."), matchesPost(post)) assertThat(replyParameters["Post.Likes.Count"], equalTo("2")) assertThat((0..1).map { replyParameters["Post.Likes.$it.ID"] }, containsInAnyOrder("Sone1", "Sone2")) } private fun verifyReplies(replyParameters: SimpleFieldSet) { assertThat(replyParameters["Post.Replies.Count"], equalTo("2")) - assertThat(replyParameters["Post.Replies.0.ID"], equalTo("ReplyId1")) - assertThat(replyParameters["Post.Replies.0.Sone"], equalTo("Sone1")) - assertThat(replyParameters["Post.Replies.0.Time"], equalTo("1000")) - assertThat(replyParameters["Post.Replies.0.Text"], equalTo("Reply 1")) - assertThat(replyParameters["Post.Replies.1.ID"], equalTo("ReplyId2")) - assertThat(replyParameters["Post.Replies.1.Sone"], equalTo("Sone2")) - assertThat(replyParameters["Post.Replies.1.Time"], equalTo("2000")) - assertThat(replyParameters["Post.Replies.1.Text"], equalTo("Reply 2")) + assertThat(replyParameters.parsePost("Post.Replies.0."), matchesReply(postReply1)) + assertThat(replyParameters.parsePost("Post.Replies.1."), matchesReply(postReply2)) } @Test