+++ /dev/null
-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);
- }
-
-}
--- /dev/null
+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")
+ }
+
+}