From: David ‘Bombe’ Roden Date: Mon, 19 Jun 2017 08:44:12 +0000 (+0200) Subject: Convert options page test to use new web page test base X-Git-Tag: 0.9.7^2~145 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2a172721a88c1e14d5b6f8bddec5a9d2a556218f;p=Sone.git Convert options page test to use new web page test base --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index be9f54b..28844b9 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -18,11 +18,7 @@ import org.junit.Test /** * Unit test for [OptionsPage]. */ -class OptionsPageTest: WebPageTest() { - - private val page = OptionsPage(template, webInterface) - - override fun getPage() = page +class OptionsPageTest: WebPageTest2(::OptionsPage) { @Before fun setupPreferences() { @@ -189,7 +185,7 @@ class OptionsPageTest: WebPageTest() { private fun verifyThatPreferencesCanBeSet(name: String, setValue: String?, expectedValue: T, getter: () -> T) { unsetCurrentSone() setMethod(POST) - addHttpRequestPart(name, setValue) + setValue?.also { addHttpRequestPart(name, it) } verifyRedirect("options.html") { assertThat(getter(), equalTo(expectedValue)) } 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 9e57539..08d00f9 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt @@ -101,6 +101,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla whenever(httpRequest.getLongParam(anyString(), anyLong())).then { getRequestParameters[it[0]]?.first()?.toLongOrNull() ?: it[1] } whenever(httpRequest.getMultipleParam(anyString())).then { getRequestParameters[it[0]]?.toTypedArray() ?: emptyArray() } whenever(httpRequest.getMultipleIntParam(anyString())).then { getRequestParameters[it[0]]?.map { it.toIntOrNull() ?: 0 } ?: emptyArray() } + whenever(httpRequest.isPartSet(anyString())).then { it[0] in postRequestParameters } whenever(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).then { postRequestParameters[it[0]]?.decode()?.take(it[1]) ?: "" } }