Remove @author tags
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / CreateReplyCommandTest.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.Post
6 import net.pterodactylus.sone.data.PostReply
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.Test
12
13 /**
14  * Unit test for [CreateReplyCommand].
15  */
16 class CreateReplyCommandTest : SoneCommandTest() {
17
18         private val post = mock<Post>()
19
20         override fun createCommand(core: Core) = CreateReplyCommand(core)
21
22         @Test
23         fun `command requires write access`() {
24                 assertThat(command.requiresWriteAccess(), equalTo(true))
25         }
26
27         @Test
28         fun `request without any parameters results in fcp exception`() {
29                 requestWithoutAnyParameterResultsInFcpException()
30         }
31
32         @Test
33         fun `request with empty Sone parameter results in fcp exception`() {
34                 requestWithEmptySoneParameterResultsInFcpException()
35         }
36
37         @Test
38         fun `request with invalid Sone parameter results in fcp exception`() {
39                 requestWithInvalidSoneParameterResultsInFcpException()
40         }
41
42         @Test
43         fun `request with valid remote Sone parameter results in fcp exception`() {
44                 requestWithValidRemoteSoneParameterResultsInFcpException()
45         }
46
47         private fun addValidLocalSoneParameter() {
48                 parameters += "Sone" to "LocalSoneId"
49                 whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
50         }
51
52         @Test
53         fun `request without post parameter results in fcp exception`() {
54                 addValidLocalSoneParameter()
55                 executeCommandAndExpectFcpException()
56         }
57
58         @Test
59         fun `request with invalid post parameter results in fcp exception`() {
60                 addValidLocalSoneParameter()
61                 parameters += "Post" to "InvalidPostId"
62                 executeCommandAndExpectFcpException()
63         }
64
65         private fun addValidPostParameter() {
66                 parameters += "Post" to "ValidPostId"
67                 whenever(core.getPost("ValidPostId")).thenReturn(post)
68         }
69
70         @Test
71         fun `request without text results in fcp exception`() {
72                 addValidLocalSoneParameter()
73                 addValidPostParameter()
74                 executeCommandAndExpectFcpException()
75         }
76
77         @Test
78         fun `complete request creates reply`() {
79                 addValidLocalSoneParameter()
80                 addValidPostParameter()
81                 parameters += "Text" to "Test"
82                 val postReply = mock<PostReply>().apply { whenever(id).thenReturn("ReplyId") }
83                 whenever(core.createReply(localSone, post, "Test")).thenReturn(postReply)
84                 val response = command.execute(parameters)
85                 assertThat(response.replyParameters["Message"], equalTo("ReplyCreated"))
86                 assertThat(response.replyParameters["Reply"], equalTo("ReplyId"))
87         }
88
89 }