🔀 Merge changes from other next branch
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / CreatePostCommandTest.kt
index 98b0a67..cfbda94 100644 (file)
@@ -1,6 +1,5 @@
 package net.pterodactylus.sone.fcp
 
-import com.google.common.base.Optional
 import com.google.common.base.Optional.absent
 import com.google.common.base.Optional.of
 import net.pterodactylus.sone.core.Core
@@ -21,7 +20,7 @@ class CreatePostCommandTest : SoneCommandTest() {
 
        @Test
        fun `command requires write access`() {
-               assertThat(command.requiresWriteAccess(), equalTo(true))
+               assertThat(command.requiresWriteAccess, equalTo(true))
        }
 
        @Test
@@ -46,53 +45,53 @@ class CreatePostCommandTest : SoneCommandTest() {
 
        @Test
        fun `request without text results in fcp exception`() {
-               parameters.putSingle("Sone", "LocalSoneId")
-               whenever(core.getSone("LocalSoneId")).thenReturn(Optional.of(localSone))
+               parameters += "Sone" to "LocalSoneId"
+               whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
                executeCommandAndExpectFcpException()
        }
 
        @Test
        fun `request with text creates post`() {
-               parameters.putSingle("Sone", "LocalSoneId")
-               parameters.putSingle("Text", "Test")
-               whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
+               parameters += "Sone" to "LocalSoneId"
+               parameters += "Text" to "Test"
+               whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
                val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
-               whenever(core.createPost(localSone, absent(), "Test")).thenReturn(post)
-               val response = command.execute(parameters, null, null)
+               whenever(core.createPost(localSone, null, "Test")).thenReturn(post)
+               val response = command.execute(parameters)
                assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
                assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
        }
 
        @Test
        fun `request with invalid recipient results in fcp exception`() {
-               parameters.putSingle("Sone", "LocalSoneId")
-               parameters.putSingle("Text", "Test")
-               parameters.putSingle("Recipient", "InvalidSoneId")
-               whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
+               parameters += "Sone" to "LocalSoneId"
+               parameters += "Text" to "Test"
+               parameters += "Recipient" to "InvalidSoneId"
+               whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
                executeCommandAndExpectFcpException()
        }
 
        @Test
        fun `request with recipient the same as the sender returns an error response`() {
-               parameters.putSingle("Sone", "LocalSoneId")
-               parameters.putSingle("Text", "Test")
-               parameters.putSingle("Recipient", "LocalSoneId")
-               whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
-               val response = command.execute(parameters, null, null)
+               parameters += "Sone" to "LocalSoneId"
+               parameters += "Text" to "Test"
+               parameters += "Recipient" to "LocalSoneId"
+               whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
+               val response = command.execute(parameters)
                assertThat(response.replyParameters["Message"], equalTo("Error"))
                assertThat(response.replyParameters["ErrorMessage"], notNullValue())
        }
 
        @Test
        fun `request with text and recipient creates post`() {
-               parameters.putSingle("Sone", "LocalSoneId")
-               parameters.putSingle("Text", "Test")
-               parameters.putSingle("Recipient", "RemoteSoneId")
-               whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
-               whenever(core.getSone("RemoteSoneId")).thenReturn(of(remoteSone))
+               parameters += "Sone" to "LocalSoneId"
+               parameters += "Text" to "Test"
+               parameters += "Recipient" to "RemoteSoneId"
+               whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
+               whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone)
                val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
-               whenever(core.createPost(localSone, of(remoteSone), "Test")).thenReturn(post)
-               val response = command.execute(parameters, null, null)
+               whenever(core.createPost(localSone, remoteSone, "Test")).thenReturn(post)
+               val response = command.execute(parameters)
                assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
                assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
        }