X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FLikeReplyCommandTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FLikeReplyCommandTest.kt;h=b5f78234018918af60684636d287c759c2e7ba54;hb=c950203916854545d27f8b5adb19ef0168a449c1;hp=0000000000000000000000000000000000000000;hpb=201ccb643923d7771cba32453279faf0344018f6;p=Sone.git 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") + } + +}