From c950203916854545d27f8b5adb19ef0168a449c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 15 Jan 2017 10:22:33 +0100 Subject: [PATCH] Add unit test for like reply command --- .../pterodactylus/sone/fcp/LikeReplyCommandTest.kt | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/fcp/LikeReplyCommandTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/LikeReplyCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/LikeReplyCommandTest.kt new file mode 100644 index 0000000..b5f7823 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/LikeReplyCommandTest.kt @@ -0,0 +1,78 @@ +package net.pterodactylus.sone.fcp + +import net.pterodactylus.sone.core.Core +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.freenet.fcp.FcpException +import net.pterodactylus.sone.test.asOptional +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [LikeReplyCommand]. + */ +class LikeReplyCommandTest : SoneCommandTest() { + + private val reply = createReply("ReplyId", mock(), mock(), 1000, "Text") + + override fun createCommand(core: Core) = LikeReplyCommand(core) + + @Before + fun setupRepliesAndSones() { + whenever(core.getPostReply("ReplyId")).thenReturn(reply.asOptional()) + whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional()) + whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional()) + } + + @Test + fun `request without parameters results in FCP exception`() { + requestWithoutAnyParameterResultsInFcpException() + } + + @Test + fun `request with invalid reply results in FCP exception`() { + parameters += "Reply" to "InvalidReplyId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request without sone results in FCP exception`() { + parameters += "Reply" to "ReplyId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with invalid sone results in FCP exception`() { + parameters += "Reply" to "ReplyId" + parameters += "Sone" to "InvalidSoneId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with remote sone results in FCP exception`() { + parameters += "Reply" to "ReplyId" + parameters += "Sone" to "RemoteSoneId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with local sone adds reply id to sone`() { + whenever(core.getLikes(reply)).thenReturn(setOf(mock(), mock(), mock())) + parameters += "Reply" to "ReplyId" + parameters += "Sone" to "LocalSoneId" + val replyParameters = command.execute(parameters).replyParameters + assertThat(replyParameters["Message"], equalTo("ReplyLiked")) + assertThat(replyParameters["LikeCount"], equalTo("3")) + verify(localSone).addLikedReplyId("ReplyId") + } + +} -- 2.7.4