Filter future replies when encoding single posts.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 26 Oct 2013 01:06:03 +0000 (03:06 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:45 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java

index 1e7a3ed..a66fdae 100644 (file)
@@ -273,7 +273,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
        protected SimpleFieldSet encodePostWithReplies(Post post, String prefix) {
                SimpleFieldSetBuilder postBuilder = createPostBuilderFromPost(post, prefix);
 
-               List<PostReply> replies = post.getReplies();
+               List<PostReply> replies = from(post.getReplies()).filter(FUTURE_REPLY_FILTER).toList();
                postBuilder.put(encodeReplies(replies, prefix));
 
                return postBuilder.get();
index c50d9ca..3ac7328 100644 (file)
@@ -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<Sone> 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.");