From 043d3bca7a88ecb04be90ab9978a6fdc0d8f7434 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 19 Jun 2017 10:33:32 +0200 Subject: [PATCH] Remove dependency on web page test base from reloading page test --- .../pterodactylus/sone/web/pages/ReloadingPageTest.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt index a281851..1a80a1b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt @@ -1,11 +1,17 @@ package net.pterodactylus.sone.web.pages +import freenet.support.api.HTTPRequest +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.util.web.Response import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import java.io.ByteArrayOutputStream +import java.net.URI import java.nio.file.Files import java.nio.file.Paths import kotlin.text.Charsets.UTF_8 @@ -13,11 +19,15 @@ import kotlin.text.Charsets.UTF_8 /** * Unit test for [ReloadingPage]. */ -class ReloadingPageTest : WebPageTest() { +class ReloadingPageTest { @Rule @JvmField val tempFolder = TemporaryFolder() private val folder by lazy { tempFolder.newFolder()!! } private val page by lazy { ReloadingPage("/prefix/", folder.path, "text/plain") } + private val freenetRequest = mock() + private val httpRequest = mock() + private val responseBytes = ByteArrayOutputStream() + private val response = Response(responseBytes) @Test fun `page returns correct path prefix`() { @@ -29,6 +39,11 @@ class ReloadingPageTest : WebPageTest() { assertThat(page.isPrefixPage, equalTo(true)) } + private fun request(uri: String) { + whenever(httpRequest.path).thenReturn(uri) + whenever(freenetRequest.uri).thenReturn(URI(uri)) + } + @Test fun `requesting invalid file results in 404`() { request("/prefix/path/file.txt") @@ -45,7 +60,7 @@ class ReloadingPageTest : WebPageTest() { assertThat(response.statusCode, equalTo(200)) assertThat(response.statusText, equalTo("OK")) assertThat(response.contentType, equalTo("text/plain")) - assertThat(responseBytes, equalTo("Hello\nWorld\n".toByteArray())) + assertThat(responseBytes.toByteArray(), equalTo("Hello\nWorld\n".toByteArray())) } } -- 2.7.4