import static com.google.common.collect.ArrayListMultimap.create;
import static com.google.common.collect.Ordering.from;
import static com.google.common.collect.Sets.newHashSet;
+import static java.util.Collections.emptySet;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
private final Multimap<Sone, Post> sonePosts = create();
private final Collection<Sone> sones = newHashSet();
private final Multimap<Post, PostReply> postReplies = create();
+ private final Multimap<String, Post> directedPosts = create();
public final Database database;
public final Core core;
return FluentIterable.from(sones).filter(Sone.LOCAL_SONE_FILTER).toList();
}
});
+ when(database.getDirectedPosts(anyString())).then(new Answer<Collection<Post>>() {
+ @Override
+ public Collection<Post> answer(InvocationOnMock invocation) throws Throwable {
+ return directedPosts.get((String) invocation.getArguments()[0]);
+ }
+ });
}
private static Core mockCore(Database database) {
private Optional<String> name = absent();
private long time;
private Profile profile = new Profile(mockedSone);
- private Optional<String> friend = absent();
+ private Collection<String> friends = emptySet();
private SoneMocker(String id) {
this.id = id;
return this;
}
- public SoneMocker withFriends(String friend) {
- this.friend = fromNullable(friend);
+ public SoneMocker withFriends(Collection<String> friends) {
+ this.friends = friends;
return this;
}
}
});
when(mockedSone.hasFriend(anyString())).thenReturn(false);
- if (friend.isPresent()) {
- when(mockedSone.hasFriend(friend.get())).thenReturn(true);
- }
+ when(mockedSone.getFriends()).thenReturn(friends);
+ when(mockedSone.hasFriend(anyString())).then(new Answer<Boolean>() {
+ @Override
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ return friends.contains(invocation.getArguments()[0]);
+ }
+ });
} else {
when(mockedSone.newPostBuilder()).thenThrow(IllegalStateException.class);
when(mockedSone.newPostReplyBuilder(anyString())).thenThrow(IllegalStateException.class);
when(post.getId()).thenReturn(id);
when(post.getSone()).thenReturn(sone);
when(post.getRecipientId()).thenReturn(recipientId);
+ if (recipientId.isPresent()) {
+ directedPosts.put(recipientId.get(), post);
+ }
when(post.getTime()).thenReturn(time);
if (text.isPresent()) {
when(post.getText()).thenReturn(text.get());