Add unit test for like reply command
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 15 Jan 2017 09:22:33 +0000 (10:22 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 15 Jan 2017 09:22:33 +0000 (10:22 +0100)
src/test/kotlin/net/pterodactylus/sone/fcp/LikeReplyCommandTest.kt [new file with mode: 0644]

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 (file)
index 0000000..b5f7823
--- /dev/null
@@ -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<Sone>(), mock<Post>(), 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<Sone>(), mock<Sone>(), mock<Sone>()))
+               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")
+       }
+
+}