Add tests for fixed Sone modification detector
[Sone.git] / src / test / java / net / pterodactylus / sone / TestPostBuilder.java
1 package net.pterodactylus.sone;
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  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
17  */
18 public class TestPostBuilder implements PostBuilder {
19
20         private final Post post = mock(Post.class);
21         private String recipientId = null;
22
23         @Override
24         public PostBuilder copyPost(Post post) throws NullPointerException {
25                 return this;
26         }
27
28         @Override
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);
33                 return this;
34         }
35
36         @Override
37         public PostBuilder randomId() {
38                 when(post.getId()).thenReturn(randomUUID().toString());
39                 return this;
40         }
41
42         @Override
43         public PostBuilder withId(String id) {
44                 when(post.getId()).thenReturn(id);
45                 return this;
46         }
47
48         @Override
49         public PostBuilder currentTime() {
50                 when(post.getTime()).thenReturn(currentTimeMillis());
51                 return this;
52         }
53
54         @Override
55         public PostBuilder withTime(long time) {
56                 when(post.getTime()).thenReturn(time);
57                 return this;
58         }
59
60         @Override
61         public PostBuilder withText(String text) {
62                 when(post.getText()).thenReturn(text);
63                 return this;
64         }
65
66         @Override
67         public PostBuilder to(String recipientId) {
68                 this.recipientId = recipientId;
69                 return this;
70         }
71
72         @Override
73         public Post build() throws IllegalStateException {
74                 when(post.getRecipientId()).thenReturn(fromNullable(recipientId));
75                 return post;
76         }
77
78 }