Convert unlock Sone page test to use new web page test base
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 18 Jun 2017 19:38:13 +0000 (21:38 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 07:59:22 +0000 (09:59 +0200)
src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt

index 1a0d63b..9cde13c 100644 (file)
@@ -14,11 +14,7 @@ import org.mockito.Mockito.verify
 /**
  * Unit test for [UnlockSonePage].
  */
 /**
  * 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`() {
 
        @Test
        fun `page returns correct path`() {
index 6cdff99..b04fc4b 100644 (file)
@@ -50,6 +50,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla
        private val getRequestParameters = mutableMapOf<String, MutableList<String>>()
        private val postRequestParameters = mutableMapOf<String, ByteArray>()
        private val allSones = mutableMapOf<String, Sone>()
        private val getRequestParameters = mutableMapOf<String, MutableList<String>>()
        private val postRequestParameters = mutableMapOf<String, ByteArray>()
        private val allSones = mutableMapOf<String, Sone>()
+       private val localSones = mutableMapOf<String, Sone>()
        private val allPosts = mutableMapOf<String, Post>()
        private val translations = mutableMapOf<String, String>()
 
        private val allPosts = mutableMapOf<String, Post>()
        private val translations = mutableMapOf<String, String>()
 
@@ -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.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() }
        }
 
                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<String>() }
                whenever(httpRequest.getMultipleIntParam(anyString())).then { getRequestParameters[it[0]]?.map { it.toIntOrNull() ?: 0 } ?: emptyArray<Int>() }
                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.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)
        }
 
        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
        }
 
                allSones[id] = sone
        }
 
+       fun addLocalSone(id: String, localSone: Sone) {
+               localSones[id] = localSone
+       }
+
        fun addPost(id: String, post: Post) {
                allPosts[id] = post
        }
        fun addPost(id: String, post: Post) {
                allPosts[id] = post
        }