From 67d172414f70c588e878c64ec8ba43f388bc93bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Oct 2013 22:30:26 +0100 Subject: [PATCH] Use verifyAnswer method in all FCP tests. --- .../sone/fcp/CreatePostCommandTest.java | 13 ++++-------- .../sone/fcp/CreateReplyCommandTest.java | 5 ++--- .../sone/fcp/DeletePostCommandTest.java | 10 +++------ .../sone/fcp/DeleteReplyCommandTest.java | 10 +++------ .../sone/fcp/GetLocalSonesCommandTest.java | 7 ++----- .../sone/fcp/GetPostFeedCommandTest.java | 24 ++++++---------------- .../sone/fcp/LockSoneCommandTest.java | 6 ++---- .../sone/fcp/UnlockSoneCommandTest.java | 6 ++---- 8 files changed, 24 insertions(+), 57 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java index f9cb1ab..a424079 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java @@ -20,13 +20,13 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; import static java.lang.System.currentTimeMillis; import static net.pterodactylus.sone.database.PostBuilder.PostCreated; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; @@ -66,9 +66,7 @@ public class CreatePostCommandTest { .put("Recipient", "OtherSone") .get(); Response response = createPostCommand.execute(createPostFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(capturingPostCreated.post, notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostCreated")); + verifyAnswer(response, "PostCreated"); assertThat(response.getReplyParameters().get("Post"), is(capturingPostCreated.post.getId())); assertThat(capturingPostCreated.post.getSone(), is(sone)); assertThat(capturingPostCreated.post.getRecipientId(), is(of("OtherSone"))); @@ -87,9 +85,7 @@ public class CreatePostCommandTest { .put("Text", "Text of the post.") .get(); Response response = createPostCommand.execute(createPostFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(capturingPostCreated.post, notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostCreated")); + verifyAnswer(response, "PostCreated"); assertThat(response.getReplyParameters().get("Post"), is(capturingPostCreated.post.getId())); assertThat(capturingPostCreated.post.getSone(), is(sone)); assertThat(capturingPostCreated.post.getRecipientId(), is(Optional.absent())); @@ -109,8 +105,7 @@ public class CreatePostCommandTest { .put("Text", "Text of the post.") .get(); Response response = createPostCommand.execute(createPostFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("Error")); + verifyAnswer(response, "Error"); assertThat(capturingPostCreated.post, nullValue()); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java index 2241eaf..36f99a8 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.fcp; import static java.lang.System.currentTimeMillis; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -64,15 +65,13 @@ public class CreateReplyCommandTest { .put("Text", "Text of the reply.") .get(); Response response = createReplyCommand.execute(createReplyFieldSet, null, DIRECT); - assertThat(response, notNullValue()); + verifyAnswer(response, "ReplyCreated"); assertThat(capturingPostReplyCreated.postReply, notNullValue()); assertThat(capturingPostReplyCreated.postReply.getId(), notNullValue()); assertThat(capturingPostReplyCreated.postReply.getPostId(), is("PostId")); assertThat(capturingPostReplyCreated.postReply.getSone(), is(sone)); assertThat(capturingPostReplyCreated.postReply.getTime(), allOf(greaterThanOrEqualTo(now), lessThanOrEqualTo(currentTimeMillis()))); assertThat(capturingPostReplyCreated.postReply.getText(), is("Text of the reply.")); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("ReplyCreated")); assertThat(response.getReplyParameters().get("Reply"), is(capturingPostReplyCreated.postReply.getId())); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java index 21214db..1e2ce7c 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java @@ -17,10 +17,10 @@ package net.pterodactylus.sone.fcp; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; import static org.mockito.ArgumentCaptor.forClass; import static org.mockito.Mockito.doNothing; @@ -57,9 +57,7 @@ public class DeletePostCommandTest { .put("Post", "PostId") .get(); Response response = deletePostCommand.execute(deletePostFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostDeleted")); + verifyAnswer(response, "PostDeleted"); assertThat(deletedPost.getValue(), is(post)); } @@ -72,9 +70,7 @@ public class DeletePostCommandTest { .put("Post", "PostId") .get(); Response response = deletePostCommand.execute(deletePostFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("Error")); + verifyAnswer(response, "Error"); assertThat(response.getReplyParameters().get("ErrorCode"), is("401")); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java index 8b7cadd..7a30808 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java @@ -17,10 +17,10 @@ package net.pterodactylus.sone.fcp; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; import static org.mockito.ArgumentCaptor.forClass; import static org.mockito.Mockito.doNothing; @@ -57,10 +57,8 @@ public class DeleteReplyCommandTest { .put("Reply", "ReplyId") .get(); Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT); - assertThat(response, notNullValue()); + verifyAnswer(response, "ReplyDeleted"); assertThat(postReplyCaptor.getValue(), is(postReply)); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("ReplyDeleted")); } @Test(expected = FcpException.class) @@ -89,9 +87,7 @@ public class DeleteReplyCommandTest { .put("Reply", "ReplyId") .get(); Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("Error")); + verifyAnswer(response, "Error"); assertThat(response.getReplyParameters().get("ErrorCode"), is("401")); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java index 0ed5204..85b1bb7 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java @@ -19,10 +19,9 @@ package net.pterodactylus.sone.fcp; import static java.lang.String.format; import static java.util.Arrays.asList; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; import java.util.Collection; import java.util.List; @@ -62,9 +61,7 @@ public class GetLocalSonesCommandTest { mocks.mockSone("RSone2").create(); SimpleFieldSet getLocalSonesFieldSet = new SimpleFieldSetBuilder().put("Message", "GetLocalSones").get(); Response response = getLocalSonesCommand.execute(getLocalSonesFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("ListLocalSones")); + verifyAnswer(response, "ListLocalSones"); Collection parsedSones = parseSones(response.getReplyParameters(), "LocalSones."); assertThat(parsedSones, matchesSones(localSones)); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java index 838b03d..e272148 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java @@ -20,11 +20,9 @@ package net.pterodactylus.sone.fcp; import static java.lang.System.currentTimeMillis; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.DAYS; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static net.pterodactylus.sone.fcp.Verifiers.verifyPostsWithReplies; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; import java.util.Collections; @@ -80,9 +78,7 @@ public class GetPostFeedCommandTest { .put("Sone", "LSone") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); + verifyAnswer(response, "PostFeed"); verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost, remotePost)); } @@ -94,9 +90,7 @@ public class GetPostFeedCommandTest { .put("StartPost", "1") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); + verifyAnswer(response, "PostFeed"); verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost, remotePost)); } @@ -108,9 +102,7 @@ public class GetPostFeedCommandTest { .put("MaxPosts", "2") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); + verifyAnswer(response, "PostFeed"); verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost)); } @@ -123,9 +115,7 @@ public class GetPostFeedCommandTest { .put("StartPost", "1") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); + verifyAnswer(response, "PostFeed"); verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost)); } @@ -137,9 +127,7 @@ public class GetPostFeedCommandTest { .put("StartPost", "10") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); + verifyAnswer(response, "PostFeed"); verifyPostsWithReplies(response.getReplyParameters(), "Posts.", Collections.emptyList()); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java index 01f9994..5ed051e 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java @@ -18,8 +18,8 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -57,9 +57,7 @@ public class LockSoneCommandTest { Response response = lockSoneCommand.execute(fields, null, null); verify(core).lockSone(eq(localSone)); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("SoneLocked")); + verifyAnswer(response, "SoneLocked"); assertThat(response.getReplyParameters().get("Sone"), is("LocalSone")); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java index 245cdb5..d73b6e3 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java @@ -18,8 +18,8 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; +import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -57,9 +57,7 @@ public class UnlockSoneCommandTest { Response response = unlockSoneCommand.execute(fields, null, null); verify(core).unlockSone(eq(localSone)); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("SoneUnlocked")); + verifyAnswer(response, "SoneUnlocked"); assertThat(response.getReplyParameters().get("Sone"), is("LocalSone")); } -- 2.7.4