X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FCreatePostCommandTest.kt;h=5fc84f07463ac2ee194ad925749c3a99857c4463;hb=ffd92ca2374c0b2218e583d02e0bdd24b8c110ae;hp=75e238e9e1d1d155a56e8153bad8cce07cae1fb7;hpb=00c0f66598af0a462cb367fbf1ad67512878cf5e;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt index 75e238e..5fc84f0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt @@ -5,7 +5,6 @@ import com.google.common.base.Optional.absent import com.google.common.base.Optional.of import net.pterodactylus.sone.core.Core import net.pterodactylus.sone.data.Post -import net.pterodactylus.sone.freenet.fcp.FcpException import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import org.hamcrest.MatcherAssert.assertThat @@ -47,55 +46,53 @@ class CreatePostCommandTest : SoneCommandTest() { @Test fun `request without text results in fcp exception`() { - parameters.putSingle("Sone", "LocalSoneId") + parameters += "Sone" to "LocalSoneId" whenever(core.getSone("LocalSoneId")).thenReturn(Optional.of(localSone)) - expectedException.expect(FcpException::class.java) - command.execute(parameters, null, null) + executeCommandAndExpectFcpException() } @Test fun `request with text creates post`() { - parameters.putSingle("Sone", "LocalSoneId") - parameters.putSingle("Text", "Test") + parameters += "Sone" to "LocalSoneId" + parameters += "Text" to "Test" whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone)) val post = mock().apply { whenever(id).thenReturn("PostId") } whenever(core.createPost(localSone, absent(), "Test")).thenReturn(post) - val response = command.execute(parameters, null, null) + 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") + parameters += "Sone" to "LocalSoneId" + parameters += "Text" to "Test" + parameters += "Recipient" to "InvalidSoneId" whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone)) - expectedException.expect(FcpException::class.java) - command.execute(parameters, null, null) + 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") + parameters += "Sone" to "LocalSoneId" + parameters += "Text" to "Test" + parameters += "Recipient" to "LocalSoneId" whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone)) - val response = command.execute(parameters, null, null) + 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") + parameters += "Sone" to "LocalSoneId" + parameters += "Text" to "Test" + parameters += "Recipient" to "RemoteSoneId" whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone)) whenever(core.getSone("RemoteSoneId")).thenReturn(of(remoteSone)) val post = mock().apply { whenever(id).thenReturn("PostId") } whenever(core.createPost(localSone, of(remoteSone), "Test")).thenReturn(post) - val response = command.execute(parameters, null, null) + val response = command.execute(parameters) assertThat(response.replyParameters.get("Message"), equalTo("PostCreated")) assertThat(response.replyParameters.get("Post"), equalTo("PostId")) }