1 package net.pterodactylus.sone.fcp
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
14 * Unit test for [CreateReplyCommand].
16 class CreateReplyCommandTest : SoneCommandTest() {
18 private val post = mock<Post>()
20 override fun createCommand(core: Core) = CreateReplyCommand(core)
23 fun `command requires write access`() {
24 assertThat(command.requiresWriteAccess(), equalTo(true))
28 fun `request without any parameters results in fcp exception`() {
29 requestWithoutAnyParameterResultsInFcpException()
33 fun `request with empty Sone parameter results in fcp exception`() {
34 requestWithEmptySoneParameterResultsInFcpException()
38 fun `request with invalid Sone parameter results in fcp exception`() {
39 requestWithInvalidSoneParameterResultsInFcpException()
43 fun `request with valid remote Sone parameter results in fcp exception`() {
44 requestWithValidRemoteSoneParameterResultsInFcpException()
47 private fun addValidLocalSoneParameter() {
48 parameters += "Sone" to "LocalSoneId"
49 whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
53 fun `request without post parameter results in fcp exception`() {
54 addValidLocalSoneParameter()
55 executeCommandAndExpectFcpException()
59 fun `request with invalid post parameter results in fcp exception`() {
60 addValidLocalSoneParameter()
61 parameters += "Post" to "InvalidPostId"
62 executeCommandAndExpectFcpException()
65 private fun addValidPostParameter() {
66 parameters += "Post" to "ValidPostId"
67 whenever(core.getPost("ValidPostId")).thenReturn(post)
71 fun `request without text results in fcp exception`() {
72 addValidLocalSoneParameter()
73 addValidPostParameter()
74 executeCommandAndExpectFcpException()
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"))