1 package net.pterodactylus.sone;
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 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
18 public class TestPostBuilder implements PostBuilder {
20 private final Post post = mock(Post.class);
21 private String recipientId = null;
24 public PostBuilder copyPost(Post post) throws NullPointerException {
29 public PostBuilder from(String senderId) {
30 final Sone sone = mock(Sone.class);
31 when(sone.getId()).thenReturn(senderId);
32 when(post.getSone()).thenReturn(sone);
37 public PostBuilder randomId() {
38 when(post.getId()).thenReturn(randomUUID().toString());
43 public PostBuilder withId(String id) {
44 when(post.getId()).thenReturn(id);
49 public PostBuilder currentTime() {
50 when(post.getTime()).thenReturn(currentTimeMillis());
55 public PostBuilder withTime(long time) {
56 when(post.getTime()).thenReturn(time);
61 public PostBuilder withText(String text) {
62 when(post.getText()).thenReturn(text);
67 public PostBuilder to(String recipientId) {
68 this.recipientId = recipientId;
73 public Post build() throws IllegalStateException {
74 when(post.getRecipientId()).thenReturn(fromNullable(recipientId));