1 package net.pterodactylus.sone.fcp
3 import net.pterodactylus.sone.core.*
4 import net.pterodactylus.sone.freenet.fcp.*
5 import net.pterodactylus.sone.test.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
9 import org.mockito.Mockito.*
12 * Unit test for [LikeReplyCommand].
14 class LikeReplyCommandTest : SoneCommandTest() {
16 private val reply = createReply("ReplyId", mock(), mock(), 1000, "Text")
18 override fun createCommand(core: Core) = LikeReplyCommand(core)
21 fun setupRepliesAndSones() {
22 whenever(core.getPostReply("ReplyId")).thenReturn(reply)
23 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone)
24 whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
28 fun `command requires write access`() {
29 assertThat(command.requiresWriteAccess, equalTo(true))
33 fun `request without parameters results in FCP exception`() {
34 requestWithoutAnyParameterResultsInFcpException()
38 fun `request with invalid reply results in FCP exception`() {
39 parameters += "Reply" to "InvalidReplyId"
40 expectedException.expect(FcpException::class.java)
41 command.execute(parameters)
45 fun `request without sone results in FCP exception`() {
46 parameters += "Reply" to "ReplyId"
47 expectedException.expect(FcpException::class.java)
48 command.execute(parameters)
52 fun `request with invalid sone results in FCP exception`() {
53 parameters += "Reply" to "ReplyId"
54 parameters += "Sone" to "InvalidSoneId"
55 expectedException.expect(FcpException::class.java)
56 command.execute(parameters)
60 fun `request with remote sone results in FCP exception`() {
61 parameters += "Reply" to "ReplyId"
62 parameters += "Sone" to "RemoteSoneId"
63 expectedException.expect(FcpException::class.java)
64 command.execute(parameters)
68 fun `request with local sone adds reply id to sone`() {
69 whenever(core.getLikes(reply)).thenReturn(setOf(mock(), mock(), mock()))
70 parameters += "Reply" to "ReplyId"
71 parameters += "Sone" to "LocalSoneId"
72 val replyParameters = command.execute(parameters).replyParameters
73 assertThat(replyParameters["Message"], equalTo("ReplyLiked"))
74 assertThat(replyParameters["LikeCount"], equalTo("3"))
75 verify(localSone).addLikedReplyId("ReplyId")