- public Sone mockLocalSone(final String id) {
- final Sone sone = mock(Sone.class);
- when(sone.isLocal()).thenReturn(true);
- initializeSoneMock(id, sone);
- when(sone.newPostBuilder()).thenReturn(new DefaultPostBuilder(database, id));
- when(sone.newPostReplyBuilder(anyString())).then(new Answer<PostReplyBuilder>() {
- @Override
- public PostReplyBuilder answer(InvocationOnMock invocation) throws Throwable {
- return new DefaultPostReplyBuilder(database, id, (String) invocation.getArguments()[0]);
- }
- });
- return sone;
- }
-
- public Sone mockRemoteSone(final String id) {
- final Sone sone = mock(Sone.class);
- when(sone.isLocal()).thenReturn(false);
- initializeSoneMock(id, sone);
- when(sone.newPostBuilder()).thenThrow(IllegalStateException.class);
- when(sone.newPostReplyBuilder(Matchers.<String>anyObject())).thenThrow(IllegalStateException.class);
- return sone;
- }
-
- private void initializeSoneMock(String id, final Sone sone) {
- when(sone.getId()).thenReturn(id);
- when(sone.getProfile()).thenReturn(new Profile(sone));
- when(core.getSone(eq(id))).thenReturn(of(sone));
- when(database.getSone(eq(id))).thenReturn(of(sone));
- when(sone.getPosts()).then(new Answer<List<Post>>() {
- @Override
- public List<Post> answer(InvocationOnMock invocationOnMock) throws Throwable {
- return from(TIME_COMPARATOR).sortedCopy(sonePosts.get(sone));
- }
- });
- when(sone.toString()).thenReturn(String.format("Sone[%s]", id));
- sones.add(sone);