Convert options page test to use new web page test base
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 08:44:12 +0000 (10:44 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 08:44:12 +0000 (10:44 +0200)
src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt

index be9f54b..28844b9 100644 (file)
@@ -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 <T> 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))
                }
index 9e57539..08d00f9 100644 (file)
@@ -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<String>() }
                whenever(httpRequest.getMultipleIntParam(anyString())).then { getRequestParameters[it[0]]?.map { it.toIntOrNull() ?: 0 } ?: emptyArray<Int>() }
+               whenever(httpRequest.isPartSet(anyString())).then { it[0] in postRequestParameters }
                whenever(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).then { postRequestParameters[it[0]]?.decode()?.take(it[1]) ?: "" }
        }