From: David ‘Bombe’ Roden Date: Sat, 26 Oct 2013 01:34:06 +0000 (+0200) Subject: Add method that verifies post replies. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7b574e45a34038aa92899edc483a1c95c15f4055;p=Sone.git Add method that verifies post replies. --- diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index 5c21071..c32c148 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -32,6 +32,8 @@ import static org.mockito.Matchers.eq; 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.core.Core; @@ -430,11 +432,19 @@ public class AbstractSoneCommandTest { SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); verifyPost(postFieldSet, "Post.", post); - assertThat(postFieldSet.getInt("Post.Replies.Count"), is(1)); - assertThat(postFieldSet.get("Post.Replies.0.ID"), is(postReply.getId())); - assertThat(postFieldSet.get("Post.Replies.0.Sone"), is(postReply.getSone().getId())); - assertThat(postFieldSet.getLong("Post.Replies.0.Time"), is(postReply.getTime())); - assertThat(postFieldSet.get("Post.Replies.0.Text"), is(postReply.getText())); + verifyPostReplies(postFieldSet, "Post.", asList(postReply)); + } + + private void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, Collection postReplies) throws FSParseException { + assertThat(postFieldSet.getInt(prefix + "Replies.Count"), is(postReplies.size())); + int postReplyIndex = 0; + for (PostReply postReply : postReplies) { + 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++; + } } @Test @@ -446,11 +456,7 @@ public class AbstractSoneCommandTest { SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); verifyPost(postFieldSet, "Post.", post); - assertThat(postFieldSet.getInt("Post.Replies.Count"), is(0)); - assertThat(postFieldSet.get("Post.Replies.0.ID"), nullValue()); - assertThat(postFieldSet.get("Post.Replies.0.Sone"), nullValue()); - assertThat(postFieldSet.get("Post.Replies.0.Time"), nullValue()); - assertThat(postFieldSet.get("Post.Replies.0.Text"), nullValue()); + verifyPostReplies(postFieldSet, "Post.", Collections.emptyList()); } @Test @@ -462,11 +468,7 @@ public class AbstractSoneCommandTest { SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); verifyPost(postFieldSet, "Post.", post); - assertThat(postFieldSet.getInt("Post.Replies.Count"), is(1)); - assertThat(postFieldSet.get("Post.Replies.0.ID"), is(postReply.getId())); - assertThat(postFieldSet.get("Post.Replies.0.Sone"), is(postReply.getSone().getId())); - assertThat(postFieldSet.getLong("Post.Replies.0.Time"), is(postReply.getTime())); - assertThat(postFieldSet.get("Post.Replies.0.Text"), is(postReply.getText())); + verifyPostReplies(postFieldSet, "Post.", asList(postReply)); } @Test