X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FMocks.java;h=34b25f3e8385b05dc6ceced331b149b8c495e5ba;hb=6dab0951c2abde1e47f01004861efd1acb9de548;hp=841b38e231cb1442d7956dcf0012b70852aa4522;hpb=84ff475ffaf47ed2461babf431babff6592d39a9;p=Sone.git 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;