Replace mark as known page with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / LikeReplyCommandTest.kt
1 package net.pterodactylus.sone.fcp
2
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.asOptional
8 import net.pterodactylus.sone.test.mock
9 import net.pterodactylus.sone.test.whenever
10 import org.hamcrest.MatcherAssert.assertThat
11 import org.hamcrest.Matchers.equalTo
12 import org.junit.Before
13 import org.junit.Test
14 import org.mockito.Mockito.verify
15
16 /**
17  * Unit test for [LikeReplyCommand].
18  */
19 class LikeReplyCommandTest : SoneCommandTest() {
20
21         private val reply = createReply("ReplyId", mock<Sone>(), mock<Post>(), 1000, "Text")
22
23         override fun createCommand(core: Core) = LikeReplyCommand(core)
24
25         @Before
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())
30         }
31
32         @Test
33         fun `command requires write access`() {
34                 assertThat(command.requiresWriteAccess(), equalTo(true))
35         }
36
37         @Test
38         fun `request without parameters results in FCP exception`() {
39                 requestWithoutAnyParameterResultsInFcpException()
40         }
41
42         @Test
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)
47         }
48
49         @Test
50         fun `request without sone results in FCP exception`() {
51                 parameters += "Reply" to "ReplyId"
52                 expectedException.expect(FcpException::class.java)
53                 command.execute(parameters)
54         }
55
56         @Test
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)
62         }
63
64         @Test
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)
70         }
71
72         @Test
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")
81         }
82
83 }