1 package net.pterodactylus.sone.test;
3 import static com.google.common.base.Optional.fromNullable;
4 import static java.lang.System.currentTimeMillis;
5 import static java.util.UUID.randomUUID;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.when;
9 import net.pterodactylus.sone.data.Post;
10 import net.pterodactylus.sone.data.Sone;
11 import net.pterodactylus.sone.database.PostBuilder;
14 * {@link PostBuilder} implementation that returns a mocked {@link Post}.
16 public class TestPostBuilder implements PostBuilder {
18 private final Post post = mock(Post.class);
19 private String recipientId = null;
22 public PostBuilder copyPost(Post post) throws NullPointerException {
27 public PostBuilder from(String senderId) {
28 final Sone sone = mock(Sone.class);
29 when(sone.getId()).thenReturn(senderId);
30 when(post.getSone()).thenReturn(sone);
35 public PostBuilder randomId() {
36 when(post.getId()).thenReturn(randomUUID().toString());
41 public PostBuilder withId(String id) {
42 when(post.getId()).thenReturn(id);
47 public PostBuilder currentTime() {
48 when(post.getTime()).thenReturn(currentTimeMillis());
53 public PostBuilder withTime(long time) {
54 when(post.getTime()).thenReturn(time);
59 public PostBuilder withText(String text) {
60 when(post.getText()).thenReturn(text);
65 public PostBuilder to(String recipientId) {
66 this.recipientId = recipientId;
71 public Post build() throws IllegalStateException {
72 when(post.getRecipientId()).thenReturn(fromNullable(recipientId));