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;
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.
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<String> postIdCaptor = forClass(String.class);
+ when(sone.newPostReplyBuilder(postIdCaptor.capture())).then(new Answer<PostReplyBuilder>() {
+ @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;