From 634e4f484de3e51a55e4dae41ed8481921597733 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 5 Nov 2013 20:20:58 +0100 Subject: [PATCH] Track liked posts. --- .../java/net/pterodactylus/sone/data/Mocks.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/java/net/pterodactylus/sone/data/Mocks.java b/src/test/java/net/pterodactylus/sone/data/Mocks.java index 8c8c93a..0e8a731 100644 --- a/src/test/java/net/pterodactylus/sone/data/Mocks.java +++ b/src/test/java/net/pterodactylus/sone/data/Mocks.java @@ -26,12 +26,14 @@ import static com.google.common.collect.Ordering.from; import static java.util.Collections.emptySet; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.impl.DefaultPostBuilder; @@ -42,8 +44,11 @@ import net.pterodactylus.sone.database.PostReplyBuilder; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.FluentIterable; +import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Ordering; +import com.google.common.collect.SetMultimap; +import org.mockito.Matchers; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -58,6 +63,7 @@ public class Mocks { private final Map sones = newHashMap(); private final Multimap postReplies = create(); private final Multimap directedPosts = create(); + private final SetMultimap postLikingSones = HashMultimap.create(); public final Database database; public final Core core; @@ -252,6 +258,26 @@ public class Mocks { return Ordering.from(Reply.TIME_COMPARATOR).sortedCopy(postReplies.get(post)); } }); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + postLikingSones.put(post, (Sone) invocation.getArguments()[0]); + return null; + } + }).when(post).like(Matchers.any()); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + postLikingSones.remove(post, (Sone) invocation.getArguments()[0]); + return null; + } + }).when(post).unlike(Matchers.any()); + when(post.getLikes()).thenAnswer(new Answer>() { + @Override + public Set answer(InvocationOnMock invocation) throws Throwable { + return postLikingSones.get(post); + } + }); return post; } -- 2.7.4