From: David ‘Bombe’ Roden Date: Sun, 22 Jan 2017 00:54:09 +0000 (+0100) Subject: Convert unit test to Kotlin X-Git-Tag: 0.9.7^2~322 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;ds=inline;h=721e99302c43d08fd2a63174273de28791c04c8a;p=Sone.git Convert unit test to Kotlin --- 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 index 3b8258e..0000000 --- a/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java +++ /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 David ‘Bombe’ Roden - */ -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 index 0000000..f63219f --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/UploadImagePageTest.kt @@ -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().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") + } + +}