From 2c1a8dbe9f2b08d78b172523bdfecddf9a33a2a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Oct 2013 21:33:17 +0100 Subject: [PATCH] Use yet another way to verify the posts. --- .../sone/fcp/GetPostFeedCommandTest.java | 25 +++++++--------------- .../java/net/pterodactylus/sone/fcp/Verifiers.java | 10 +++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java index 97e9e81..838b03d 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java @@ -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.emptyList()); } @Test(expected = FcpException.class) diff --git a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java index e282210..fd47592 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java +++ b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java @@ -64,4 +64,14 @@ public class Verifiers { } } + static void verifyPostsWithReplies(SimpleFieldSet postFieldSet, String prefix, Collection 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++; + } + } + } -- 2.7.4