Replace test for bookmark page with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 2 Feb 2017 19:31:30 +0000 (20:31 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 2 Feb 2017 19:31:30 +0000 (20:31 +0100)
src/test/java/net/pterodactylus/sone/web/BookmarkPageTest.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/web/BookmarkPageTest.java b/src/test/java/net/pterodactylus/sone/web/BookmarkPageTest.java
deleted file mode 100644 (file)
index ddba2c5..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.util.web.Method;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link BookmarkPage}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class BookmarkPageTest extends WebPageTest {
-
-       private final BookmarkPage page = new BookmarkPage(template, webInterface);
-
-       @Test
-       public void pathIsSetCorrectly() {
-               assertThat(page.getPath(), is("bookmark.html"));
-       }
-
-       @Test
-       public void getRequestDoesNotBookmarkAnythingAndDoesNotRedirect() throws Exception {
-               page.processTemplate(freenetRequest, templateContext);
-               verify(core, never()).bookmarkPost(any(Post.class));
-       }
-
-       @Test
-       public void postIsBookmarkedCorrectly() throws Exception {
-               setupRequest();
-               Post post = mock(Post.class);
-               addPost("post-id", post);
-               expectedException.expect(redirectsTo("return-page.html"));
-               try {
-                       page.processTemplate(freenetRequest, templateContext);
-               } finally {
-                       verify(core).bookmarkPost(post);
-               }
-       }
-
-       private void setupRequest() {
-               request("", Method.POST);
-               addHttpRequestParameter("post", "post-id");
-               addHttpRequestParameter("returnPage", "return-page.html");
-       }
-
-       @Test
-       public void nonExistentPostIsNotBookmarked() throws Exception {
-               setupRequest();
-               addPost("post-id", null);
-               expectedException.expect(redirectsTo("return-page.html"));
-               try {
-                       page.processTemplate(freenetRequest, templateContext);
-               } finally {
-                       verify(core, never()).bookmarkPost(any(Post.class));
-               }
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt
new file mode 100644 (file)
index 0000000..2a2c816
--- /dev/null
@@ -0,0 +1,56 @@
+package net.pterodactylus.sone.web
+
+import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.util.web.Method.POST
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.never
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [BookmarkPage].
+ */
+class BookmarkPageTest : WebPageTest() {
+
+       private val page = BookmarkPage(template, webInterface)
+       override fun getPage() = page
+
+       @Test
+       fun `path is set correctly`() {
+               assertThat(page.path, equalTo("bookmark.html"))
+       }
+
+       @Test
+       fun `get request does not bookmark anything and does not redirect`() {
+               page.handleRequest(freenetRequest, templateContext)
+               verify(core, never()).bookmarkPost(any())
+       }
+
+       private fun setupBookmarkRequest() {
+               request("", POST)
+               addHttpRequestParameter("returnPage", "return-page.html")
+               addHttpRequestParameter("post", "post-id")
+       }
+
+       @Test
+       fun `post is bookmarked correctly`() {
+               setupBookmarkRequest()
+               val post = mock<Post>()
+               addPost("post-id", post)
+               verifyRedirect("return-page.html") {
+                       verify(core).bookmarkPost(post)
+               }
+       }
+
+       @Test
+       fun `non-existing post is not bookmarked`() {
+               setupBookmarkRequest()
+               verifyRedirect("return-page.html") {
+                       verify(core, never()).bookmarkPost(any())
+               }
+       }
+
+}