X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FTestPostBuilder.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FTestPostBuilder.java;h=19338576c2e1e49fc4bab6f2143796b74ff9f9e6;hb=eb32457356fac09e16ec98394c1b5d48f9dfba84;hp=0000000000000000000000000000000000000000;hpb=ec655d61682a70063c1cf540fe3e41613aaf71a5;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/test/TestPostBuilder.java b/src/test/java/net/pterodactylus/sone/test/TestPostBuilder.java new file mode 100644 index 0000000..1933857 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/test/TestPostBuilder.java @@ -0,0 +1,78 @@ +package net.pterodactylus.sone.test; + +import static com.google.common.base.Optional.fromNullable; +import static java.lang.System.currentTimeMillis; +import static java.util.UUID.randomUUID; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.database.PostBuilder; + +/** + * {@link PostBuilder} implementation that returns a mocked {@link Post}. + * + * @author David ‘Bombe’ Roden + */ +public class TestPostBuilder implements PostBuilder { + + private final Post post = mock(Post.class); + private String recipientId = null; + + @Override + public PostBuilder copyPost(Post post) throws NullPointerException { + return this; + } + + @Override + public PostBuilder from(String senderId) { + final Sone sone = mock(Sone.class); + when(sone.getId()).thenReturn(senderId); + when(post.getSone()).thenReturn(sone); + return this; + } + + @Override + public PostBuilder randomId() { + when(post.getId()).thenReturn(randomUUID().toString()); + return this; + } + + @Override + public PostBuilder withId(String id) { + when(post.getId()).thenReturn(id); + return this; + } + + @Override + public PostBuilder currentTime() { + when(post.getTime()).thenReturn(currentTimeMillis()); + return this; + } + + @Override + public PostBuilder withTime(long time) { + when(post.getTime()).thenReturn(time); + return this; + } + + @Override + public PostBuilder withText(String text) { + when(post.getText()).thenReturn(text); + return this; + } + + @Override + public PostBuilder to(String recipientId) { + this.recipientId = recipientId; + return this; + } + + @Override + public Post build() throws IllegalStateException { + when(post.getRecipientId()).thenReturn(fromNullable(recipientId)); + return post; + } + +}