Use more concise SAM implementation
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / DeleteReplyCommandTest.kt
1 package net.pterodactylus.sone.fcp
2
3 import com.google.common.base.Optional.of
4 import net.pterodactylus.sone.core.Core
5 import net.pterodactylus.sone.data.PostReply
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.sone.test.whenever
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.junit.Test
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [DeleteReplyCommand].
15  */
16 class DeleteReplyCommandTest : SoneCommandTest() {
17
18         private val remotePostReply = mock<PostReply>().apply { whenever(sone).thenReturn(remoteSone) }
19         private val localPostReply = mock<PostReply>().apply { whenever(sone).thenReturn(localSone) }
20
21         override fun createCommand(core: Core) = DeleteReplyCommand(core)
22
23         @Test
24         fun `command requires write access`() {
25                 assertThat(command.requiresWriteAccess(), equalTo(true))
26         }
27
28         @Test
29         fun `request without any parameters results in fcp exception`() {
30                 requestWithoutAnyParameterResultsInFcpException()
31         }
32
33         @Test
34         fun `request with invalid post reply parameter results in fcp exception`() {
35                 parameters += "Reply" to "InvalidReplyId"
36                 executeCommandAndExpectFcpException()
37         }
38
39         @Test
40         fun `request with remote post reply parameter results in error response`() {
41             parameters += "Reply" to "RemoteReplyId"
42                 whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(remotePostReply))
43                 val response = command.execute(parameters)
44                 assertThat(response.replyParameters["Message"], equalTo("Error"))
45                 assertThat(response.replyParameters["ErrorCode"], equalTo("401"))
46         }
47
48         @Test
49         fun `request with local post reply parameter deletes reply`() {
50             parameters += "Reply" to "RemoteReplyId"
51                 whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(localPostReply))
52                 val response = command.execute(parameters)
53                 assertThat(response.replyParameters["Message"], equalTo("ReplyDeleted"))
54                 verify(core).deleteReply(localPostReply)
55         }
56
57 }