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 [LikePostCommand].
14 class LikePostCommandTest : SoneCommandTest() {
16 private val post = createPost("PostId", mock(), null, 1000, "Text")
18 override fun createCommand(core: Core) = LikePostCommand(core)
21 fun setupPostAndSones() {
22 whenever(core.getPost("PostId")).thenReturn(post)
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 post id results in FCP exception`() {
39 parameters += "Post" to "InvalidPostId"
40 expectedException.expect(FcpException::class.java)
41 command.execute(parameters)
45 fun `request with missing local sone results in FCP exception`() {
46 parameters += "Post" to "PostId"
47 expectedException.expect(FcpException::class.java)
48 command.execute(parameters)
52 fun `request with invalid sone results in FCP exception`() {
53 parameters += "Post" to "PostId"
54 parameters += "Sone" to "InvalidSoneId"
55 expectedException.expect(FcpException::class.java)
56 command.execute(parameters)
60 fun `request with valid remote sone results in FCP exception`() {
61 parameters += "Post" to "PostId"
62 parameters += "Sone" to "RemoteSoneId"
63 expectedException.expect(FcpException::class.java)
64 command.execute(parameters)
68 fun `request with valid parameters adds post to liked posts for sone`() {
69 whenever(core.getLikes(post)).thenReturn(setOf(mock(), mock(), mock()))
70 parameters += "Post" to "PostId"
71 parameters += "Sone" to "LocalSoneId"
72 val replyParameters = command.execute(parameters).replyParameters
73 assertThat(replyParameters["Message"], equalTo("PostLiked"))
74 assertThat(replyParameters["LikeCount"], equalTo("3"))
75 verify(localSone).addLikedPostId("PostId")