From: David ‘Bombe’ Roden Date: Wed, 30 Oct 2013 20:38:04 +0000 (+0100) Subject: Move more post and reply verifiers to the Verifiers class. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7662db855611501efe295eece8ab1bca3773722d;p=Sone.git Move more post and reply verifiers to the Verifiers class. --- diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index 964f97a..dab94a4 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -18,14 +18,15 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; -import static com.google.common.collect.FluentIterable.from; import static java.lang.System.currentTimeMillis; import static java.util.Arrays.asList; import static java.util.UUID.randomUUID; import static java.util.concurrent.TimeUnit.DAYS; -import static net.pterodactylus.sone.data.Reply.FUTURE_REPLY_FILTER; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeSone; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeString; +import static net.pterodactylus.sone.fcp.Verifiers.verifyPostWithReplies; +import static net.pterodactylus.sone.fcp.Verifiers.verifyPosts; +import static net.pterodactylus.sone.fcp.Verifiers.verifyPostsWithReplies; import static net.pterodactylus.sone.template.SoneAccessor.getNiceName; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -34,8 +35,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.Collection; -import java.util.Collections; import java.util.List; import net.pterodactylus.sone.data.Mocks; @@ -355,20 +354,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - verifyPost(postFieldSet, "Post.", post); - verifyPostReplies(postFieldSet, "Post.", asList(postReply)); - } - - private void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, Collection postReplies) throws FSParseException { - assertThat(postFieldSet.getInt(prefix + "Replies.Count"), is(from(postReplies).filter(FUTURE_REPLY_FILTER).size())); - int postReplyIndex = 0; - for (PostReply postReply : from(postReplies).filter(FUTURE_REPLY_FILTER)) { - assertThat(postFieldSet.get(prefix + "Replies." + postReplyIndex + ".ID"), is(postReply.getId())); - assertThat(postFieldSet.get(prefix + "Replies." + postReplyIndex + ".Sone"), is(postReply.getSone().getId())); - assertThat(postFieldSet.getLong(prefix + "Replies." + postReplyIndex + ".Time"), is(postReply.getTime())); - assertThat(postFieldSet.get(prefix + "Replies." + postReplyIndex + ".Text"), is(postReply.getText())); - postReplyIndex++; - } + verifyPostWithReplies(postFieldSet, "Post.", post); } @Test @@ -379,8 +365,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - verifyPost(postFieldSet, "Post.", post); - verifyPostReplies(postFieldSet, "Post.", Collections.emptyList()); + verifyPostWithReplies(postFieldSet, "Post.", post); } @Test @@ -391,8 +376,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - verifyPost(postFieldSet, "Post.", post); - verifyPostReplies(postFieldSet, "Post.", asList(postReply)); + verifyPostWithReplies(postFieldSet, "Post.", post); } @Test @@ -406,15 +390,6 @@ public class AbstractSoneCommandTest { verifyPosts(postFieldSet, "Posts.", asList(post1, post2)); } - private void verifyPosts(SimpleFieldSet postFieldSet, String prefix, Collection posts) throws FSParseException { - assertThat(postFieldSet.getInt(prefix + "Count"), is(posts.size())); - int postIndex = 0; - for (Post post : posts) { - verifyPost(postFieldSet, prefix + postIndex + ".", post); - postIndex++; - } - } - @Test public void testEncodingPostsWithRecipientWithoutReplies() throws FSParseException { Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create(); @@ -441,16 +416,6 @@ public class AbstractSoneCommandTest { verifyPostsWithReplies(postFieldSet, "Posts.", asList(post1, post2)); } - private void verifyPostsWithReplies(SimpleFieldSet postFieldSet, String prefix, Collection posts) throws FSParseException { - assertThat(postFieldSet.getInt(prefix + "Count"), is(posts.size())); - int postIndex = 0; - for (Post post : posts) { - verifyPost(postFieldSet, prefix + postIndex + ".", post); - verifyPostReplies(postFieldSet, prefix + postIndex + ".", post.getReplies()); - postIndex++; - } - } - @Test public void testEncodingPostsWithRecipientAndReplies() throws FSParseException { Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create(); diff --git a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java index fd47592..82f28d9 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java +++ b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java @@ -48,6 +48,15 @@ public class Verifiers { assertThat(replyParameters.get(format("%sText", prefix)), is(post.getText())); } + static void verifyPosts(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); + 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())); @@ -74,4 +83,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()); + } + }