From 959c51e271d7da6566ecd13b912ede0d5e627b3d 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:06:03 +0200 Subject: [PATCH] Filter future replies when encoding single posts. --- .../sone/fcp/AbstractSoneCommand.java | 2 +- .../sone/fcp/AbstractSoneCommandTest.java | 28 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 1e7a3ed..a66fdae 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -273,7 +273,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand { protected SimpleFieldSet encodePostWithReplies(Post post, String prefix) { SimpleFieldSetBuilder postBuilder = createPostBuilderFromPost(post, prefix); - List replies = post.getReplies(); + List replies = from(post.getReplies()).filter(FUTURE_REPLY_FILTER).toList(); postBuilder.put(encodeReplies(replies, prefix)); return postBuilder.get(); diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index c50d9ca..3ac7328 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -230,11 +230,17 @@ public class AbstractSoneCommandTest { PostReply postReply = mock(PostReply.class); when(postReply.getId()).thenReturn(randomUUID().toString()); when(postReply.getSone()).thenReturn(sone); - when(postReply.getTime()).thenReturn((long) (Math.random() * Long.MAX_VALUE)); + when(postReply.getTime()).thenReturn(System.currentTimeMillis()); when(postReply.getText()).thenReturn(text); return postReply; } + private PostReply createFuturePostReply(Sone sone, String text) { + PostReply postReply = createPostReply(sone, text); + when(postReply.getTime()).thenReturn(System.currentTimeMillis() + 86400000); + return postReply; + } + @Test public void testEncodingLikes() throws FSParseException { List likes = prepareMultipleSones(); @@ -436,6 +442,26 @@ public class AbstractSoneCommandTest { } @Test + public void testEncodingAPostWithoutRecipientWithFutureReplies() throws FSParseException { + Sone sone = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test", "First", "M.", "Last", (long) (Math.random() * Long.MAX_VALUE)); + Post post = createPost(sone, null, (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + PostReply postReply = createFuturePostReply(sone, "Reply."); + 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())); + 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()); + } + + @Test public void testEncodingAPostWithRecipientAndReplies() throws FSParseException { Sone sone = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test", "First", "M.", "Last", (long) (Math.random() * Long.MAX_VALUE)); Post post = createPost(sone, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text."); -- 2.7.4