From 57152c775159b6bcd24aad27faeb2b05891d8dc0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 28 Jun 2017 07:19:46 +0200 Subject: [PATCH] Use web page test in reloading page test --- .../sone/web/pages/ReloadingPageTest.kt | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 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 1a80a1b..7ebb052 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt @@ -1,17 +1,11 @@ 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 @@ -24,10 +18,10 @@ 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) + private val webPageTest = WebPageTest() + private val freenetRequest = webPageTest.freenetRequest + private val responseBytes = webPageTest.responseContent + private val response = webPageTest.response @Test fun `page returns correct path prefix`() { @@ -39,14 +33,9 @@ class ReloadingPageTest { 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") + webPageTest.request("/prefix/path/file.txt") page.handleRequest(freenetRequest, response) assertThat(response.statusCode, equalTo(404)) assertThat(response.statusText, equalTo("Not found")) @@ -55,7 +44,7 @@ class ReloadingPageTest { @Test fun `requesting valid file results in 200 and delivers file`() { Files.write(Paths.get(folder.path, "file.txt"), listOf("Hello", "World"), UTF_8) - request("/prefix/path/file.txt") + webPageTest.request("/prefix/path/file.txt") page.handleRequest(freenetRequest, response) assertThat(response.statusCode, equalTo(200)) assertThat(response.statusText, equalTo("OK")) -- 2.7.4