From: David ‘Bombe’ Roden Date: Sun, 27 Oct 2013 21:15:09 +0000 (+0100) Subject: Return a useful reply builder on a mocked Sone. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6dab0951c2abde1e47f01004861efd1acb9de548;p=Sone.git Return a useful reply builder on a mocked Sone. --- diff --git a/src/test/java/net/pterodactylus/sone/data/Mocks.java b/src/test/java/net/pterodactylus/sone/data/Mocks.java index 841b38e..34b25f3 100644 --- a/src/test/java/net/pterodactylus/sone/data/Mocks.java +++ b/src/test/java/net/pterodactylus/sone/data/Mocks.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.data; import static com.google.common.base.Optional.of; +import static org.mockito.ArgumentCaptor.forClass; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -25,9 +26,14 @@ import static org.mockito.Mockito.when; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.impl.DefaultPostBuilder; +import net.pterodactylus.sone.data.impl.DefaultPostReplyBuilder; import net.pterodactylus.sone.database.Database; +import net.pterodactylus.sone.database.PostReplyBuilder; import com.google.common.base.Optional; +import org.mockito.ArgumentCaptor; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; /** * Mocks reusable in multiple tests. @@ -49,12 +55,19 @@ public class Mocks { return database; } - public static Sone mockLocalSone(Core core, String id) { + public static Sone mockLocalSone(Core core, final String id) { Sone sone = mock(Sone.class); when(sone.getId()).thenReturn(id); when(sone.isLocal()).thenReturn(true); - Database database = core.getDatabase(); + final Database database = core.getDatabase(); when(sone.newPostBuilder()).thenReturn(new DefaultPostBuilder(database, id)); + final ArgumentCaptor postIdCaptor = forClass(String.class); + when(sone.newPostReplyBuilder(postIdCaptor.capture())).then(new Answer() { + @Override + public PostReplyBuilder answer(InvocationOnMock invocationOnMock) throws Throwable { + return new DefaultPostReplyBuilder(database, id, postIdCaptor.getValue()); + } + }); when(core.getSone(eq(id))).thenReturn(of(sone)); when(database.getSone(eq(id))).thenReturn(of(sone)); return sone;