🎨 Replace test post builder with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 6 Aug 2020 18:57:08 +0000 (20:57 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 6 Aug 2020 18:57:08 +0000 (20:57 +0200)
src/test/java/net/pterodactylus/sone/test/TestPostBuilder.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/test/TestPostBuilder.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/test/TestPostBuilder.java b/src/test/java/net/pterodactylus/sone/test/TestPostBuilder.java
deleted file mode 100644 (file)
index 6cb7828..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-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}.
- */
-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;
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/test/TestPostBuilder.kt b/src/test/kotlin/net/pterodactylus/sone/test/TestPostBuilder.kt
new file mode 100644 (file)
index 0000000..4c9efe7
--- /dev/null
@@ -0,0 +1,54 @@
+package net.pterodactylus.sone.test
+
+import com.google.common.base.Optional
+import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.database.PostBuilder
+import java.util.UUID
+
+/**
+ * [PostBuilder] implementation that returns a mocked [Post].
+ */
+class TestPostBuilder : PostBuilder {
+
+       private val post = mock<Post>()
+       private var recipientId: String? = null
+
+       override fun copyPost(post: Post): PostBuilder = this
+
+       override fun from(senderId: String): PostBuilder = apply {
+               val sone = mock<Sone>()
+               whenever(sone.id).thenReturn(senderId)
+               whenever(post.sone).thenReturn(sone)
+       }
+
+       override fun randomId(): PostBuilder = apply {
+               whenever(post.id).thenReturn(UUID.randomUUID().toString())
+       }
+
+       override fun withId(id: String): PostBuilder = apply {
+               whenever(post.id).thenReturn(id)
+       }
+
+       override fun currentTime(): PostBuilder = apply {
+               whenever(post.time).thenReturn(System.currentTimeMillis())
+       }
+
+       override fun withTime(time: Long): PostBuilder = apply {
+               whenever(post.time).thenReturn(time)
+       }
+
+       override fun withText(text: String): PostBuilder = apply {
+               whenever(post.text).thenReturn(text)
+       }
+
+       override fun to(recipientId: String): PostBuilder = apply {
+               this.recipientId = recipientId
+       }
+
+       override fun build(): Post = post
+                       .also {
+                               whenever(post.recipientId).thenReturn(Optional.fromNullable(recipientId))
+                       }
+
+}