Return mocked replies to a post.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Oct 2013 06:20:06 +0000 (07:20 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:50 +0000 (22:25 +0100)
src/test/java/net/pterodactylus/sone/data/Mocks.java

index 07ca567..21e5925 100644 (file)
@@ -38,6 +38,7 @@ import net.pterodactylus.sone.database.PostReplyBuilder;
 import com.google.common.base.Optional;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Ordering;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -50,6 +51,7 @@ public class Mocks {
 
        private final Multimap<Sone, Post> sonePosts = create();
        private final Collection<Sone> sones = newHashSet();
+       private final Multimap<Post, PostReply> postReplies = create();
        public final Database database;
        public final Core core;
 
@@ -158,6 +160,12 @@ public class Mocks {
                        when(post.getSone()).thenReturn(sone);
                        when(database.getPost(eq(id))).thenReturn(of(post));
                        sonePosts.put(sone, post);
+                       when(post.getReplies()).then(new Answer<List<PostReply>>() {
+                               @Override
+                               public List<PostReply> answer(InvocationOnMock invocation) throws Throwable {
+                                       return Ordering.from(Reply.TIME_COMPARATOR).sortedCopy(postReplies.get(post));
+                               }
+                       });
                        return post;
                }