From: David ‘Bombe’ Roden Date: Sun, 18 Jun 2017 19:38:13 +0000 (+0200) Subject: Convert unlock Sone page test to use new web page test base X-Git-Tag: 0.9.7^2~157 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=298ee0947a7a05071583a62ffc2fb149a437b710;p=Sone.git Convert unlock Sone page test to use new web page test base --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt index 1a0d63b..9cde13c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt @@ -14,11 +14,7 @@ import org.mockito.Mockito.verify /** * Unit test for [UnlockSonePage]. */ -class UnlockSonePageTest : WebPageTest() { - - private val page = UnlockSonePage(template, webInterface) - - override fun getPage() = page +class UnlockSonePageTest: WebPageTest2(::UnlockSonePage) { @Test fun `page returns correct path`() { 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 6cdff99..b04fc4b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt @@ -50,6 +50,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla private val getRequestParameters = mutableMapOf>() private val postRequestParameters = mutableMapOf() private val allSones = mutableMapOf() + private val localSones = mutableMapOf() private val allPosts = mutableMapOf() private val translations = mutableMapOf() @@ -58,6 +59,8 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla whenever(core.preferences).thenReturn(preferences) whenever(core.sones).then { allSones.values } whenever(core.getSone(anyString())).then { allSones[it[0]].asOptional() } + whenever(core.localSones).then { localSones.values } + whenever(core.getLocalSone(anyString())).then { localSones[it[0]] } whenever(core.getPost(anyString())).then { allPosts[it[0]].asOptional() } } @@ -81,7 +84,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.getPartAsStringFailsafe(anyString(), anyInt())).then { postRequestParameters[it[0]]?.decode() } + whenever(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).then { postRequestParameters[it[0]]?.decode()?.take(it[1]) ?: "" } } private fun ByteArray.decode(charset: Charset = UTF_8) = String(this, charset) @@ -115,6 +118,10 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla allSones[id] = sone } + fun addLocalSone(id: String, localSone: Sone) { + localSones[id] = localSone + } + fun addPost(id: String, post: Post) { allPosts[id] = post }