Convert unit test to Kotlin
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 22 Jan 2017 00:54:09 +0000 (01:54 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 22 Jan 2017 00:56:07 +0000 (01:56 +0100)
src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UploadImagePageTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java b/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java
deleted file mode 100644 (file)
index 3b8258e..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.util.web.Method;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit test for {@link UploadImagePageTest}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UploadImagePageTest extends WebPageTest {
-
-       private final UploadImagePage uploadImagePage = new UploadImagePage(template, webInterface);
-
-       private final Album parentAlbum = mock(Album.class);
-
-       @Before
-       public void setupParentAlbum() {
-               when(core.getAlbum("parent-id")).thenReturn(parentAlbum);
-               when(parentAlbum.getSone()).thenReturn(currentSone);
-       }
-
-       @Test
-       public void uploadingAnImageWithoutTitleRedirectsToEmptyImageTitlePage() throws Exception {
-               request("", Method.POST);
-               when(httpRequest.getPartAsStringFailsafe(eq("parent"), anyInt())).thenReturn("parent-id");
-               when(httpRequest.getPartAsStringFailsafe(eq("title"), anyInt())).thenReturn("  ");
-               expectedException.expect(redirectsTo("emptyImageTitle.html"));
-               uploadImagePage.processTemplate(freenetRequest, templateContext);
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/UploadImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/UploadImagePageTest.kt
new file mode 100644 (file)
index 0000000..f63219f
--- /dev/null
@@ -0,0 +1,29 @@
+package net.pterodactylus.sone.web
+
+import net.pterodactylus.sone.data.Album
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.util.web.Method
+import org.junit.Test
+
+/**
+ * Unit test for [UploadImagePage].
+ */
+class UploadImagePageTest : WebPageTest() {
+
+       private val parentAlbum = mock<Album>().apply {
+               whenever(sone).thenReturn(currentSone)
+       }
+
+       override fun getPage() = UploadImagePage(template, webInterface)
+
+       @Test
+       fun `post request with empty name redirects to error page`() {
+               request("", Method.POST)
+               addAlbum("parent-id", parentAlbum)
+               addHttpRequestParameter("parent", "parent-id")
+               addHttpRequestParameter("title", " ")
+               verifyRedirect("emptyImageTitle.html")
+       }
+
+}