🔀 Merge branch 'release/v82'
[Sone.git] / pterodactylus / sone / fcp / LikeReplyCommandTest.kt
1 package net.pterodactylus.sone.fcp
2
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.*
8 import org.junit.*
9 import org.mockito.Mockito.*
10
11 /**
12  * Unit test for [LikeReplyCommand].
13  */
14 class LikeReplyCommandTest : SoneCommandTest() {
15
16         private val reply = createReply("ReplyId", mock(), mock(), 1000, "Text")
17
18         override fun createCommand(core: Core) = LikeReplyCommand(core)
19
20         @Before
21         fun setupRepliesAndSones() {
22                 whenever(core.getPostReply("ReplyId")).thenReturn(reply)
23                 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone)
24                 whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
25         }
26
27         @Test
28         fun `command requires write access`() {
29                 assertThat(command.requiresWriteAccess, equalTo(true))
30         }
31
32         @Test
33         fun `request without parameters results in FCP exception`() {
34                 requestWithoutAnyParameterResultsInFcpException()
35         }
36
37         @Test
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)
42         }
43
44         @Test
45         fun `request without sone results in FCP exception`() {
46                 parameters += "Reply" to "ReplyId"
47                 expectedException.expect(FcpException::class.java)
48                 command.execute(parameters)
49         }
50
51         @Test
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)
57         }
58
59         @Test
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)
65         }
66
67         @Test
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")
76         }
77
78 }