Use yet another way to verify the posts.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Oct 2013 20:33:17 +0000 (21:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:50 +0000 (22:25 +0100)
src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/Verifiers.java

index 97e9e81..838b03d 100644 (file)
@@ -20,13 +20,14 @@ 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.verifyPost;
-import static net.pterodactylus.sone.fcp.Verifiers.verifyPostReplies;
+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;
+
 import net.pterodactylus.sone.data.Mocks;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
@@ -82,11 +83,7 @@ public class GetPostFeedCommandTest {
                assertThat(response, notNullValue());
                assertThat(response.getReplyParameters(), notNullValue());
                assertThat(response.getReplyParameters().get("Message"), is("PostFeed"));
-               assertThat(response.getReplyParameters().getInt("Posts.Count"), is(3));
-               verifyPost(response.getReplyParameters(), "Posts.0.", localPost);
-               verifyPostReplies(response.getReplyParameters(), "Posts.0.Replies.", asList(friendReplyToLocalPost, remoteReplyToLocalPost));
-               verifyPost(response.getReplyParameters(), "Posts.1.", friendPost);
-               verifyPost(response.getReplyParameters(), "Posts.2.", remotePost);
+               verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost, remotePost));
        }
 
        @Test
@@ -100,9 +97,7 @@ public class GetPostFeedCommandTest {
                assertThat(response, notNullValue());
                assertThat(response.getReplyParameters(), notNullValue());
                assertThat(response.getReplyParameters().get("Message"), is("PostFeed"));
-               assertThat(response.getReplyParameters().getInt("Posts.Count"), is(2));
-               verifyPost(response.getReplyParameters(), "Posts.0.", friendPost);
-               verifyPost(response.getReplyParameters(), "Posts.1.", remotePost);
+               verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost, remotePost));
        }
 
        @Test
@@ -116,10 +111,7 @@ public class GetPostFeedCommandTest {
                assertThat(response, notNullValue());
                assertThat(response.getReplyParameters(), notNullValue());
                assertThat(response.getReplyParameters().get("Message"), is("PostFeed"));
-               assertThat(response.getReplyParameters().getInt("Posts.Count"), is(2));
-               verifyPost(response.getReplyParameters(), "Posts.0.", localPost);
-               verifyPostReplies(response.getReplyParameters(), "Posts.0.Replies.", asList(friendReplyToLocalPost, remoteReplyToLocalPost));
-               verifyPost(response.getReplyParameters(), "Posts.1.", friendPost);
+               verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost));
        }
 
        @Test
@@ -134,8 +126,7 @@ public class GetPostFeedCommandTest {
                assertThat(response, notNullValue());
                assertThat(response.getReplyParameters(), notNullValue());
                assertThat(response.getReplyParameters().get("Message"), is("PostFeed"));
-               assertThat(response.getReplyParameters().getInt("Posts.Count"), is(1));
-               verifyPost(response.getReplyParameters(), "Posts.0.", friendPost);
+               verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost));
        }
 
        @Test
@@ -149,7 +140,7 @@ public class GetPostFeedCommandTest {
                assertThat(response, notNullValue());
                assertThat(response.getReplyParameters(), notNullValue());
                assertThat(response.getReplyParameters().get("Message"), is("PostFeed"));
-               assertThat(response.getReplyParameters().getInt("Posts.Count"), is(0));
+               verifyPostsWithReplies(response.getReplyParameters(), "Posts.", Collections.<Post>emptyList());
        }
 
        @Test(expected = FcpException.class)
index e282210..fd47592 100644 (file)
@@ -64,4 +64,14 @@ public class Verifiers {
                }
        }
 
+       static void verifyPostsWithReplies(SimpleFieldSet postFieldSet, String prefix, Collection<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);
+                       verifyPostReplies(postFieldSet, prefix + postIndex + ".Replies.", post.getReplies());
+                       postIndex++;
+               }
+       }
+
 }