1 package net.pterodactylus.sone.fcp
3 import net.pterodactylus.sone.core.Core
4 import net.pterodactylus.sone.data.Post
5 import net.pterodactylus.sone.data.Sone
6 import net.pterodactylus.sone.freenet.fcp.FcpException
7 import net.pterodactylus.sone.test.mock
8 import net.pterodactylus.sone.test.whenever
9 import net.pterodactylus.sone.utils.asOptional
10 import org.hamcrest.MatcherAssert.assertThat
11 import org.hamcrest.Matchers.equalTo
12 import org.junit.Before
14 import org.mockito.Mockito.verify
17 * Unit test for [LikeReplyCommand].
19 class LikeReplyCommandTest : SoneCommandTest() {
21 private val reply = createReply("ReplyId", mock<Sone>(), mock<Post>(), 1000, "Text")
23 override fun createCommand(core: Core) = LikeReplyCommand(core)
26 fun setupRepliesAndSones() {
27 whenever(core.getPostReply("ReplyId")).thenReturn(reply.asOptional())
28 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional())
29 whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional())
33 fun `command requires write access`() {
34 assertThat(command.requiresWriteAccess(), equalTo(true))
38 fun `request without parameters results in FCP exception`() {
39 requestWithoutAnyParameterResultsInFcpException()
43 fun `request with invalid reply results in FCP exception`() {
44 parameters += "Reply" to "InvalidReplyId"
45 expectedException.expect(FcpException::class.java)
46 command.execute(parameters)
50 fun `request without sone results in FCP exception`() {
51 parameters += "Reply" to "ReplyId"
52 expectedException.expect(FcpException::class.java)
53 command.execute(parameters)
57 fun `request with invalid sone results in FCP exception`() {
58 parameters += "Reply" to "ReplyId"
59 parameters += "Sone" to "InvalidSoneId"
60 expectedException.expect(FcpException::class.java)
61 command.execute(parameters)
65 fun `request with remote sone results in FCP exception`() {
66 parameters += "Reply" to "ReplyId"
67 parameters += "Sone" to "RemoteSoneId"
68 expectedException.expect(FcpException::class.java)
69 command.execute(parameters)
73 fun `request with local sone adds reply id to sone`() {
74 whenever(core.getLikes(reply)).thenReturn(setOf(mock<Sone>(), mock<Sone>(), mock<Sone>()))
75 parameters += "Reply" to "ReplyId"
76 parameters += "Sone" to "LocalSoneId"
77 val replyParameters = command.execute(parameters).replyParameters
78 assertThat(replyParameters["Message"], equalTo("ReplyLiked"))
79 assertThat(replyParameters["LikeCount"], equalTo("3"))
80 verify(localSone).addLikedReplyId("ReplyId")