From d20861b75602e3a12e354f2c19dca26fcf7b3e5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 19 Jun 2017 23:34:27 +0200 Subject: [PATCH] Convert get image page test to use new web page test base --- .../net/pterodactylus/sone/web/pages/GetImagePageTest.kt | 16 ++++++++++------ .../net/pterodactylus/sone/web/pages/WebPageTest2.kt | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/GetImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/GetImagePageTest.kt index 151f1ae..6c34e3f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/GetImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/GetImagePageTest.kt @@ -9,9 +9,13 @@ import org.junit.Test /** * Unit test for [GetImagePage]. */ -class GetImagePageTest : WebPageTest() { +class GetImagePageTest { - private val page = GetImagePage(webInterface) + private val scaffolding = WebPageTest2() + private val page = GetImagePage(scaffolding.webInterface) + private val freenetRequest = scaffolding.freenetRequest + private val response = scaffolding.response + private val responseContent = scaffolding.responseContent @Test fun `page returns correct path`() { @@ -34,7 +38,7 @@ class GetImagePageTest : WebPageTest() { assertThat(response.statusCode, equalTo(404)) assertThat(response.statusText, equalTo("Not found.")) assertThat(response.contentType, equalTo("text/html; charset=utf-8")) - assertThat(responseBytes, equalTo(ByteArray(0))) + assertThat(responseContent.toByteArray(), equalTo(ByteArray(0))) } @Test @@ -43,12 +47,12 @@ class GetImagePageTest : WebPageTest() { mimeType = "image/test" imageData = ByteArray(5, Int::toByte) } - addHttpRequestParameter("image", "temp-id") - addTemporaryImage("temp-id", image) + scaffolding.addHttpRequestParameter("image", "temp-id") + scaffolding.addTemporaryImage("temp-id", image) page.handleRequest(freenetRequest, response) assertThat(response.statusCode, equalTo(200)) assertThat(response.contentType, equalTo("image/test")) - assertThat(responseBytes, equalTo(ByteArray(5, Int::toByte))) + assertThat(responseContent.toByteArray(), equalTo(ByteArray(5, Int::toByte))) println(response.headers.map { it.name to it.iterator().asSequence().toList() }) assertThat(response.headers.map { it.name to it.iterator().asSequence().toList() }, contains( "Content-Disposition" to listOf("attachment; filename=temp-id.test") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt index 5ec3ead..69ac20a 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt @@ -9,6 +9,7 @@ import net.pterodactylus.sone.data.Image import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.data.TemporaryImage import net.pterodactylus.sone.freenet.wot.OwnIdentity import net.pterodactylus.sone.test.deepMock import net.pterodactylus.sone.test.get @@ -91,6 +92,7 @@ open class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTemplatePa whenever(core.getAlbum(anyString())).then { allAlbums[it[0]] } whenever(core.getImage(anyString())).then { allImages[it[0]]} whenever(core.getImage(anyString(), anyBoolean())).then { allImages[it[0]]} + whenever(core.getTemporaryImage(anyString())).thenReturn(null) } private fun setupWebInterface() { @@ -190,6 +192,10 @@ open class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTemplatePa translations[key] = value } + fun addTemporaryImage(id: String, temporaryImage: TemporaryImage) { + whenever(core.getTemporaryImage(id)).thenReturn(temporaryImage) + } + fun verifyNoRedirect(assertions: () -> Unit) { var caughtException: Exception? = null try { -- 2.7.4