+ public class PostReplyMocker {
+
+ private final PostReply postReply = mock(PostReply.class);
+ private final String id;
+ private final Sone sone;
+ private Optional<Post> post = absent();
+ private long time;
+ private Optional<String> text = absent();
+
+ public PostReplyMocker(String id, Sone sone) {
+ this.id = id;
+ this.sone = sone;
+ }
+
+ public PostReplyMocker inReplyTo(Post post) {
+ this.post = fromNullable(post);
+ return this;
+ }
+
+ public PostReplyMocker withTime(long time) {
+ this.time = time;
+ return this;
+ }
+
+ public PostReplyMocker withText(String text) {
+ this.text = fromNullable(text);
+ return this;
+ }
+
+ public PostReply create() {
+ when(postReply.getId()).thenReturn(id);
+ when(postReply.getSone()).thenReturn(sone);
+ when(postReply.getTime()).thenReturn(time);
+ when(database.getPostReply(eq(id))).thenReturn(of(postReply));
+ if (post.isPresent()) {
+ postReplies.put(post.get(), postReply);
+ }
+ if (text.isPresent()) {
+ when(postReply.getText()).thenReturn(text.get());
+ }
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ postReplyLikingSones.put(postReply, (Sone) invocation.getArguments()[0]);
+ return null;
+ }
+ }).when(postReply).like(Matchers.<Sone>any());
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ postReplyLikingSones.remove(postReply, invocation.getArguments()[0]);
+ return null;
+ }
+ }).when(postReply).unlike(Matchers.<Sone>any());
+ when(postReply.getLikes()).thenAnswer(new Answer<Set<Sone>>() {
+ @Override
+ public Set<Sone> answer(InvocationOnMock invocation) throws Throwable {
+ return postReplyLikingSones.get(postReply);
+ }
+ });
+ return postReply;
+ }
+ }
+