1 package net.pterodactylus.sone.fcp
3 import net.pterodactylus.sone.core.Core
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.freenet.fcp.FcpException
6 import net.pterodactylus.sone.test.asOptional
7 import net.pterodactylus.sone.test.mock
8 import net.pterodactylus.sone.test.whenever
9 import org.hamcrest.MatcherAssert.assertThat
10 import org.hamcrest.Matchers.equalTo
11 import org.junit.Before
13 import org.mockito.Mockito.verify
16 * Unit test for [LikePostCommand].
18 class LikePostCommandTest : SoneCommandTest() {
20 private val post = createPost("PostId", mock<Sone>(), null, 1000, "Text")
22 override fun createCommand(core: Core) = LikePostCommand(core)
25 fun setupPostAndSones() {
26 whenever(core.getPost("PostId")).thenReturn(post.asOptional())
27 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional())
28 whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional())
32 fun `command requires write access`() {
33 assertThat(command.requiresWriteAccess(), equalTo(true))
37 fun `request without parameters results in FCP exception`() {
38 requestWithoutAnyParameterResultsInFcpException()
42 fun `request with invalid post id results in FCP exception`() {
43 parameters += "Post" to "InvalidPostId"
44 expectedException.expect(FcpException::class.java)
45 command.execute(parameters)
49 fun `request with missing local sone results in FCP exception`() {
50 parameters += "Post" to "PostId"
51 expectedException.expect(FcpException::class.java)
52 command.execute(parameters)
56 fun `request with invalid sone results in FCP exception`() {
57 parameters += "Post" to "PostId"
58 parameters += "Sone" to "InvalidSoneId"
59 expectedException.expect(FcpException::class.java)
60 command.execute(parameters)
64 fun `request with valid remote sone results in FCP exception`() {
65 parameters += "Post" to "PostId"
66 parameters += "Sone" to "RemoteSoneId"
67 expectedException.expect(FcpException::class.java)
68 command.execute(parameters)
72 fun `request with valid parameters adds post to liked posts for sone`() {
73 whenever(core.getLikes(post)).thenReturn(setOf(mock<Sone>(), mock<Sone>(), mock<Sone>()))
74 parameters += "Post" to "PostId"
75 parameters += "Sone" to "LocalSoneId"
76 val replyParameters = command.execute(parameters).replyParameters
77 assertThat(replyParameters["Message"], equalTo("PostLiked"))
78 assertThat(replyParameters["LikeCount"], equalTo("3"))
79 verify(localSone).addLikedPostId("PostId")