Use verifyAnswer method in all FCP tests.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Oct 2013 21:30:26 +0000 (22:30 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:51 +0000 (22:25 +0100)
src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java

index f9cb1ab..a424079 100644 (file)
@@ -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.<String>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());
        }
 
index 2241eaf..36f99a8 100644 (file)
@@ -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()));
        }
 
index 21214db..1e2ce7c 100644 (file)
 
 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"));
        }
 
index 8b7cadd..7a30808 100644 (file)
 
 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"));
        }
 
index 0ed5204..85b1bb7 100644 (file)
@@ -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<ParsedSone> parsedSones = parseSones(response.getReplyParameters(), "LocalSones.");
                assertThat(parsedSones, matchesSones(localSones));
        }
index 838b03d..e272148 100644 (file)
@@ -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.<Post>emptyList());
        }
 
index 01f9994..5ed051e 100644 (file)
@@ -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"));
        }
 
index 245cdb5..d73b6e3 100644 (file)
@@ -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"));
        }