From f479ac8ae786d02c07a14bd0cce5e09776ca9c35 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:00:11 +0100 Subject: [PATCH] Use different method to verify a number of replies. --- .../pterodactylus/sone/fcp/GetPostFeedCommandTest.java | 12 ++++-------- src/test/java/net/pterodactylus/sone/fcp/Verifiers.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java index e54f338..97e9e81 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java @@ -21,7 +21,7 @@ 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.verifyPostReply; +import static net.pterodactylus.sone.fcp.Verifiers.verifyPostReplies; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -63,7 +63,7 @@ public class GetPostFeedCommandTest { public void setup() { remoteSone = mocks.mockSone("RSone").create(); friendSone = mocks.mockSone("FSone").create(); - localSone = mocks.mockSone("LSone").local().withFriends(asList(friendSone.getId())).create(); + localSone = mocks.mockSone("LSone").local().withFriends(asList(friendSone.getId(), "NonExistingSone")).create(); localPost = mocks.mockPost(localSone, "LPost").withTime(daysBefore(11)).withText("My post.").create(); friendReplyToLocalPost = mocks.mockPostReply(friendSone, "FReply").inReplyTo(localPost).withTime(daysBefore(9)).withText("No.").create(); remoteReplyToLocalPost = mocks.mockPostReply(remoteSone, "RReply").inReplyTo(localPost).withTime(daysBefore(7)).withText("Yes.").create(); @@ -84,9 +84,7 @@ public class GetPostFeedCommandTest { assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); assertThat(response.getReplyParameters().getInt("Posts.Count"), is(3)); verifyPost(response.getReplyParameters(), "Posts.0.", localPost); - assertThat(response.getReplyParameters().getInt("Posts.0.Replies.Count"), is(2)); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.0.", friendReplyToLocalPost); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.1.", remoteReplyToLocalPost); + verifyPostReplies(response.getReplyParameters(), "Posts.0.Replies.", asList(friendReplyToLocalPost, remoteReplyToLocalPost)); verifyPost(response.getReplyParameters(), "Posts.1.", friendPost); verifyPost(response.getReplyParameters(), "Posts.2.", remotePost); } @@ -120,9 +118,7 @@ public class GetPostFeedCommandTest { assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); assertThat(response.getReplyParameters().getInt("Posts.Count"), is(2)); verifyPost(response.getReplyParameters(), "Posts.0.", localPost); - assertThat(response.getReplyParameters().getInt("Posts.0.Replies.Count"), is(2)); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.0.", friendReplyToLocalPost); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.1.", remoteReplyToLocalPost); + verifyPostReplies(response.getReplyParameters(), "Posts.0.Replies.", asList(friendReplyToLocalPost, remoteReplyToLocalPost)); verifyPost(response.getReplyParameters(), "Posts.1.", friendPost); } diff --git a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java index 3b6e3a0..e282210 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java +++ b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java @@ -17,16 +17,22 @@ package net.pterodactylus.sone.fcp; +import static com.google.common.collect.FluentIterable.from; 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 java.util.Collection; + import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import freenet.node.FSParseException; import freenet.support.SimpleFieldSet; +import org.hamcrest.CoreMatchers; + /** * Verifiers used throughout the {@link net.pterodactylus.sone.fcp} package. * @@ -49,4 +55,13 @@ public class Verifiers { assertThat(replyParameters.get(format("%sText", prefix)), is(postReply.getText())); } + static void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, Collection 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)) { + verifyPostReply(postFieldSet, prefix + postReplyIndex + ".", postReply); + postReplyIndex++; + } + } + } -- 2.7.4