From c088dd5a2896d777cc30c5676583782bfa923729 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 13 Jan 2017 20:29:14 +0100 Subject: [PATCH] Use += operator to add values to parameters --- .../sone/fcp/CreatePostCommandTest.kt | 24 +++++++++++----------- .../sone/fcp/CreateReplyCommandTest.kt | 8 ++++---- .../sone/fcp/DeletePostCommandTest.kt | 6 +++--- .../sone/fcp/DeleteReplyCommandTest.kt | 6 +++--- .../pterodactylus/sone/fcp/GetPostCommandTest.kt | 14 ++++++------- .../sone/fcp/GetPostFeedCommandTest.kt | 14 ++++++------- .../pterodactylus/sone/fcp/GetPostsCommandTest.kt | 2 +- .../net/pterodactylus/sone/fcp/SoneCommandTest.kt | 8 ++++---- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt index 6d2cc81..5fc84f0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt @@ -46,15 +46,15 @@ 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)) 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) @@ -65,18 +65,18 @@ class CreatePostCommandTest : SoneCommandTest() { @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)) 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) assertThat(response.replyParameters["Message"], equalTo("Error")) @@ -85,9 +85,9 @@ class CreatePostCommandTest : SoneCommandTest() { @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") } diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt index b30b765..f464de4 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt @@ -45,7 +45,7 @@ class CreateReplyCommandTest : SoneCommandTest() { } private fun addValidLocalSoneParameter() { - parameters.putSingle("Sone", "LocalSoneId") + parameters += "Sone" to "LocalSoneId" whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone)) } @@ -58,12 +58,12 @@ class CreateReplyCommandTest : SoneCommandTest() { @Test fun `request with invalid post parameter results in fcp exception`() { addValidLocalSoneParameter() - parameters.putSingle("Post", "InvalidPostId") + parameters += "Post" to "InvalidPostId" executeCommandAndExpectFcpException() } private fun addValidPostParameter() { - parameters.putSingle("Post", "ValidPostId") + parameters += "Post" to "ValidPostId" whenever(core.getPost("ValidPostId")).thenReturn(of(post)) } @@ -78,7 +78,7 @@ class CreateReplyCommandTest : SoneCommandTest() { fun `complete request creates reply`() { addValidLocalSoneParameter() addValidPostParameter() - parameters.putSingle("Text", "Test") + parameters += "Text" to "Test" val postReply = mock().apply { whenever(id).thenReturn("ReplyId") } whenever(core.createReply(localSone, post, "Test")).thenReturn(postReply) val response = command.execute(parameters) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt index a2b4198..751ad24 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt @@ -31,13 +31,13 @@ class DeletePostCommandTest : SoneCommandTest() { @Test fun `request with invalid post parameter results in fcp exception`() { - parameters.putSingle("Post", "InvalidPostId") + parameters += "Post" to "InvalidPostId" executeCommandAndExpectFcpException() } @Test fun `request with post from remote sone returns error response`() { - parameters.putSingle("Post", "RemotePostId") + parameters += "Post" to "RemotePostId" whenever(core.getPost("RemotePostId")).thenReturn(of(postFromRemoteSone)) val response = command.execute(parameters) assertThat(response.replyParameters["Message"], equalTo("Error")) @@ -46,7 +46,7 @@ class DeletePostCommandTest : SoneCommandTest() { @Test fun `request with post from local sone deletes posts`() { - parameters.putSingle("Post", "LocalPostId") + parameters += "Post" to "LocalPostId" whenever(core.getPost("LocalPostId")).thenReturn(of(postFromLocalSone)) val response = command.execute(parameters) assertThat(response.replyParameters["Message"], equalTo("PostDeleted")) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.kt index 57c4c30..013b1c1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.kt @@ -32,13 +32,13 @@ class DeleteReplyCommandTest : SoneCommandTest() { @Test fun `request with invalid post reply parameter results in fcp exception`() { - parameters.putSingle("Reply", "InvalidReplyId") + parameters += "Reply" to "InvalidReplyId" executeCommandAndExpectFcpException() } @Test fun `request with remote post reply parameter results in error response`() { - parameters.putSingle("Reply", "RemoteReplyId") + parameters += "Reply" to "RemoteReplyId" whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(remotePostReply)) val response = command.execute(parameters) assertThat(response.replyParameters["Message"], equalTo("Error")) @@ -47,7 +47,7 @@ class DeleteReplyCommandTest : SoneCommandTest() { @Test fun `request with local post reply parameter deletes reply`() { - parameters.putSingle("Reply", "RemoteReplyId") + parameters += "Reply" to "RemoteReplyId" whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(localPostReply)) val response = command.execute(parameters) assertThat(response.replyParameters["Message"], equalTo("ReplyDeleted")) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt index e830daf..1b4fa2e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt @@ -49,7 +49,7 @@ class GetPostCommandTest : SoneCommandTest() { @Test fun `request with invalid post parameter results in fcp exception`() { - parameters.putSingle("Post", "InvalidPostId") + parameters += "Post" to "InvalidPostId" executeCommandAndExpectFcpException() } @@ -68,7 +68,7 @@ class GetPostCommandTest : SoneCommandTest() { @Test fun `request with valid post parameter returns post response`() { - parameters.putSingle("Post", "ValidPostId") + parameters += "Post" to "ValidPostId" val replyParameters = command.execute(parameters).replyParameters verifyPostWithLikes(replyParameters) assertThat(replyParameters["Post.Recipient"], nullValue()) @@ -77,8 +77,8 @@ class GetPostCommandTest : SoneCommandTest() { @Test fun `request with valid post parameter without replies returns post response without replies`() { - parameters.putSingle("Post", "ValidPostId") - parameters.putSingle("IncludeReplies", "false") + parameters += "Post" to "ValidPostId" + parameters += "IncludeReplies" to "false" val replyParameters = command.execute(parameters).replyParameters verifyPostWithLikes(replyParameters) assertThat(replyParameters["Post.Recipient"], nullValue()) @@ -87,7 +87,7 @@ class GetPostCommandTest : SoneCommandTest() { @Test fun `request with valid post parameter returns post response with recipient`() { - parameters.putSingle("Post", "ValidPostId") + parameters += "Post" to "ValidPostId" whenever(post.recipientId).thenReturn("Sone2".asOptional()) val replyParameters = command.execute(parameters).replyParameters verifyPostWithLikes(replyParameters) @@ -97,8 +97,8 @@ class GetPostCommandTest : SoneCommandTest() { @Test fun `request with valid post parameter without replies returns post response without replies but with recipient`() { - parameters.putSingle("Post", "ValidPostId") - parameters.putSingle("IncludeReplies", "false") + parameters += "Post" to "ValidPostId" + parameters += "IncludeReplies" to "false" whenever(post.recipientId).thenReturn("Sone2".asOptional()) val replyParameters = command.execute(parameters).replyParameters verifyPostWithLikes(replyParameters) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.kt index c2f0a7a..b972a53 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.kt @@ -56,7 +56,7 @@ class GetPostFeedCommandTest : SoneCommandTest() { } private fun setupAllPostsAndReplies() { - parameters.putSingle("Sone", "ValidSoneId") + parameters += "Sone" to "ValidSoneId" whenever(localSone.id).thenReturn("ValidSoneId") whenever(core.getSone("ValidSoneId")).thenReturn(localSone.asOptional()) whenever(core.getSone("Friend1")).thenReturn(friend1.asOptional()) @@ -133,7 +133,7 @@ class GetPostFeedCommandTest : SoneCommandTest() { @Test fun `request with larger start than number of posts returns empty feed`() { setupAllPostsAndReplies() - parameters.putSingle("StartPost", "20") + parameters += "StartPost" to "20" val replyParameters = command.execute(parameters).replyParameters assertThat(replyParameters["Message"], equalTo("PostFeed")) assertThat(replyParameters["Posts.Count"], equalTo("0")) @@ -142,7 +142,7 @@ class GetPostFeedCommandTest : SoneCommandTest() { @Test fun `request with max posts of 2 returns the first two posts`() { setupAllPostsAndReplies() - parameters.putSingle("MaxPosts", "2") + parameters += "MaxPosts" to "2" val replyParameters = command.execute(parameters).replyParameters assertThat(replyParameters["Message"], equalTo("PostFeed")) assertThat(replyParameters["Posts.Count"], equalTo("2")) @@ -154,8 +154,8 @@ class GetPostFeedCommandTest : SoneCommandTest() { @Test fun `request with max posts of 2 and start post of 1 returns the center two posts`() { setupAllPostsAndReplies() - parameters.putSingle("StartPost", "1") - parameters.putSingle("MaxPosts", "2") + parameters += "StartPost" to "1" + parameters += "MaxPosts" to "2" val replyParameters = command.execute(parameters).replyParameters assertThat(replyParameters["Message"], equalTo("PostFeed")) assertThat(replyParameters["Posts.Count"], equalTo("2")) @@ -167,8 +167,8 @@ class GetPostFeedCommandTest : SoneCommandTest() { @Test fun `request with max posts of 2 and start post of 3 returns the last post`() { setupAllPostsAndReplies() - parameters.putSingle("StartPost", "3") - parameters.putSingle("MaxPosts", "2") + parameters += "StartPost" to "3" + parameters += "MaxPosts" to "2" val replyParameters = command.execute(parameters).replyParameters assertThat(replyParameters["Message"], equalTo("PostFeed")) assertThat(replyParameters["Posts.Count"], equalTo("1")) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostsCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostsCommandTest.kt index 007240a..d90ec1c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostsCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostsCommandTest.kt @@ -52,7 +52,7 @@ class GetPostsCommandTest : SoneCommandTest() { whenever(core.getSone("LocalSone")).thenReturn(localSone.asOptional()) whenever(core.getSone("ValidSoneId")).thenReturn(remoteSone.asOptional()) whenever(remoteSone.posts).thenReturn(listOf(post2, post1)) - parameters.putSingle("Sone", "ValidSoneId") + parameters += "Sone" to "ValidSoneId" } private fun verifyFirstPost(replyParameters: SimpleFieldSet, index: Int = 0) { diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt index 3d5ccef..086bbb3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt @@ -80,22 +80,22 @@ abstract class SoneCommandTest { } protected fun requestWithEmptySoneParameterResultsInFcpException() { - parameters.putSingle("Sone", null) + parameters += "Sone" to null executeCommandAndExpectFcpException() } protected fun requestWithInvalidSoneParameterResultsInFcpException() { - parameters.putSingle("Sone", "InvalidSoneId") + parameters += "Sone" to "InvalidSoneId" executeCommandAndExpectFcpException() } fun requestWithValidRemoteSoneParameterResultsInFcpException() { - parameters.putSingle("Sone", "RemoteSoneId") + parameters += "Sone" to "RemoteSoneId" whenever(core.getSone("RemoteSoneId")).thenReturn(Optional.of(remoteSone)) executeCommandAndExpectFcpException() } - protected operator fun SimpleFieldSet.plusAssign(keyValue: Pair) = putSingle(keyValue.first, keyValue.second) + protected operator fun SimpleFieldSet.plusAssign(keyValue: Pair) = putSingle(keyValue.first, keyValue.second) protected fun SimpleFieldSet.parsePost(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Sone", "Recipient", "Time", "Text") protected fun SimpleFieldSet.parseReply(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Sone", "Time", "Text") -- 2.7.4