From ec0589a84453ee2018a5aab6341b90924fde467f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 26 Oct 2013 03:33:32 +0200 Subject: [PATCH] Add method that verifies a post. --- .../sone/fcp/AbstractSoneCommandTest.java | 38 ++++++++-------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index 7ce8c6b..5c21071 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -401,11 +401,15 @@ public class AbstractSoneCommandTest { Post post = createPost(sone, null, (long) (Math.random() * Long.MAX_VALUE), "Some Text."); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePost(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), nullValue()); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); + } + + private void verifyPost(SimpleFieldSet postFieldSet, String prefix, Post post) throws FSParseException { + assertThat(postFieldSet.get(prefix + "ID"), is(post.getId())); + assertThat(postFieldSet.get(prefix + "Sone"), is(post.getSone().getId())); + assertThat(postFieldSet.get(prefix + "Recipient"), is(post.getRecipientId().orNull())); + assertThat(postFieldSet.getLong(prefix + "Time"), is(post.getTime())); + assertThat(postFieldSet.get(prefix + "Text"), is(post.getText())); } @Test @@ -414,11 +418,7 @@ public class AbstractSoneCommandTest { Post post = createPost(sone, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text."); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePost(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); } @Test @@ -429,11 +429,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), nullValue()); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + 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())); @@ -449,11 +445,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), nullValue()); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + 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()); @@ -469,11 +461,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + 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())); -- 2.7.4