Verify Lists instead of Collections.
[Sone.git] / src / test / java / net / pterodactylus / sone / fcp / Verifiers.java
index fd47592..d3d9f69 100644 (file)
@@ -22,11 +22,13 @@ import static java.lang.String.format;
 import static net.pterodactylus.sone.data.Reply.FUTURE_REPLY_FILTER;
 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;
 
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.freenet.fcp.Command.Response;
 
 import freenet.node.FSParseException;
 import freenet.support.SimpleFieldSet;
@@ -40,6 +42,12 @@ import org.hamcrest.CoreMatchers;
  */
 public class Verifiers {
 
+       static void verifyAnswer(Response response, String messageName) {
+               assertThat(response, notNullValue());
+               assertThat(response.getReplyParameters(), notNullValue());
+               assertThat(response.getReplyParameters().get("Message"), is(messageName));
+       }
+
        static void verifyPost(SimpleFieldSet replyParameters, String prefix, Post post) throws FSParseException {
                assertThat(replyParameters.get(format("%sID", prefix)), is(post.getId()));
                assertThat(replyParameters.get(format("%sSone", prefix)), is(post.getSone().getId()));
@@ -48,6 +56,15 @@ public class Verifiers {
                assertThat(replyParameters.get(format("%sText", prefix)), is(post.getText()));
        }
 
+       static void verifyPosts(SimpleFieldSet postFieldSet, String prefix, List<Post> posts) throws FSParseException {
+               assertThat(postFieldSet.getInt(prefix + "Count"), CoreMatchers.is(posts.size()));
+               int postIndex = 0;
+               for (Post post : posts) {
+                       verifyPost(postFieldSet, prefix + postIndex + ".", post);
+                       postIndex++;
+               }
+       }
+
        static void verifyPostReply(SimpleFieldSet replyParameters, String prefix, PostReply postReply) throws FSParseException {
                assertThat(replyParameters.get(format("%sID", prefix)), is(postReply.getId()));
                assertThat(replyParameters.get(format("%sSone", prefix)), is(postReply.getSone().getId()));
@@ -55,7 +72,7 @@ public class Verifiers {
                assertThat(replyParameters.get(format("%sText", prefix)), is(postReply.getText()));
        }
 
-       static void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, Collection<PostReply> postReplies) throws FSParseException {
+       static void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, List<PostReply> postReplies) throws FSParseException {
                assertThat(postFieldSet.getInt(prefix + "Count"), CoreMatchers.is(from(postReplies).filter(FUTURE_REPLY_FILTER).size()));
                int postReplyIndex = 0;
                for (PostReply postReply : from(postReplies).filter(FUTURE_REPLY_FILTER)) {
@@ -64,7 +81,7 @@ public class Verifiers {
                }
        }
 
-       static void verifyPostsWithReplies(SimpleFieldSet postFieldSet, String prefix, Collection<Post> posts) throws FSParseException {
+       static void verifyPostsWithReplies(SimpleFieldSet postFieldSet, String prefix, List<Post> posts) throws FSParseException {
                assertThat(postFieldSet.getInt(prefix + "Count"), CoreMatchers.is(posts.size()));
                int postIndex = 0;
                for (Post post : posts) {
@@ -74,4 +91,9 @@ public class Verifiers {
                }
        }
 
+       static void verifyPostWithReplies(SimpleFieldSet postFieldSet, String prefix, Post post) throws FSParseException {
+               verifyPost(postFieldSet, prefix, post);
+               verifyPostReplies(postFieldSet, prefix + "Replies.", post.getReplies());
+       }
+
 }