🔀 Merge branch 'master' into next
[Sone.git] / src / test / java / net / pterodactylus / sone / test / TestPostBuilder.java
1 package net.pterodactylus.sone.test;
2
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;
8
9 import net.pterodactylus.sone.data.Post;
10 import net.pterodactylus.sone.data.Sone;
11 import net.pterodactylus.sone.database.PostBuilder;
12
13 /**
14  * {@link PostBuilder} implementation that returns a mocked {@link Post}.
15  */
16 public class TestPostBuilder implements PostBuilder {
17
18         private final Post post = mock(Post.class);
19         private String recipientId = null;
20
21         @Override
22         public PostBuilder copyPost(Post post) throws NullPointerException {
23                 return this;
24         }
25
26         @Override
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);
31                 return this;
32         }
33
34         @Override
35         public PostBuilder randomId() {
36                 when(post.getId()).thenReturn(randomUUID().toString());
37                 return this;
38         }
39
40         @Override
41         public PostBuilder withId(String id) {
42                 when(post.getId()).thenReturn(id);
43                 return this;
44         }
45
46         @Override
47         public PostBuilder currentTime() {
48                 when(post.getTime()).thenReturn(currentTimeMillis());
49                 return this;
50         }
51
52         @Override
53         public PostBuilder withTime(long time) {
54                 when(post.getTime()).thenReturn(time);
55                 return this;
56         }
57
58         @Override
59         public PostBuilder withText(String text) {
60                 when(post.getText()).thenReturn(text);
61                 return this;
62         }
63
64         @Override
65         public PostBuilder to(String recipientId) {
66                 this.recipientId = recipientId;
67                 return this;
68         }
69
70         @Override
71         public Post build() throws IllegalStateException {
72                 when(post.getRecipientId()).thenReturn(fromNullable(recipientId));
73                 return post;
74         }
75
76 }