Replace new page test with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 24 May 2017 17:36:16 +0000 (19:36 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 24 May 2017 17:36:16 +0000 (19:36 +0200)
src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java b/src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java
deleted file mode 100644 (file)
index 2811e8b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-package net.pterodactylus.sone.web.pages;
-
-import static java.util.Arrays.asList;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.List;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-
-import com.google.common.base.Optional;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit test for {@link NewPage}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class NewPageTest extends WebPageTest {
-
-       private final NewPage newPage = new NewPage(template, webInterface);
-
-       @Before
-       public void setupNumberOfPostsPerPage() {
-               webInterface.getCore().getPreferences().setPostsPerPage(5);
-       }
-
-       @Test
-       public void postsAreNotDuplicatedWhenTheyComeFromBothNewPostsAndNewRepliesNotifications() throws Exception {
-               // given
-               Post extraPost = mock(Post.class);
-               List<Post> posts = asList(mock(Post.class), mock(Post.class));
-               List<PostReply> postReplies = asList(mock(PostReply.class), mock(PostReply.class));
-               when(postReplies.get(0).getPost()).thenReturn(Optional.of(posts.get(0)));
-               when(postReplies.get(1).getPost()).thenReturn(Optional.of(extraPost));
-               when(webInterface.getNewPosts(currentSone)).thenReturn(posts);
-               when(webInterface.getNewReplies(currentSone)).thenReturn(postReplies);
-
-               // when
-               newPage.processTemplate(freenetRequest, templateContext);
-
-               // then
-               List<Post> renderedPosts = templateContext.get("posts", List.class);
-               assertThat(renderedPosts, containsInAnyOrder(posts.get(0), posts.get(1), extraPost));
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt
new file mode 100644 (file)
index 0000000..72d87f8
--- /dev/null
@@ -0,0 +1,44 @@
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.data.PostReply
+import net.pterodactylus.sone.test.asOptional
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.sone.test.whenever
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.containsInAnyOrder
+import org.junit.Before
+import org.junit.Test
+import java.util.Arrays.asList
+
+/**
+ * Unit test for [NewPage].
+ */
+class NewPageTest: WebPageTest() {
+
+       private val page = NewPage(template, webInterface)
+
+       override fun getPage() = page
+
+       @Before
+       fun setupNumberOfPostsPerPage() {
+               webInterface.core.preferences.postsPerPage = 5
+       }
+
+       @Test
+       fun `posts are not duplicated when they come from both new posts and new replies notifications`() {
+               val extraPost = mock<Post>()
+               val posts = asList(mock<Post>(), mock<Post>())
+               val postReplies = asList(mock<PostReply>(), mock<PostReply>())
+               whenever(postReplies[0].post).thenReturn(posts[0].asOptional())
+               whenever(postReplies[1].post).thenReturn(extraPost.asOptional())
+               whenever(webInterface.getNewPosts(currentSone)).thenReturn(posts)
+               whenever(webInterface.getNewReplies(currentSone)).thenReturn(postReplies)
+
+               verifyNoRedirect {
+                       val renderedPosts = templateContext.get<List<Post>>("posts", List::class.java)
+                       assertThat(renderedPosts, containsInAnyOrder(posts[0], posts[1], extraPost))
+               }
+       }
+
+}