♻️ Add L10n to FreenetRequest, WebInterface to SoneRequest
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / WebPageTest.kt
index 1bf75c0..d654b09 100644 (file)
@@ -20,7 +20,7 @@ import net.pterodactylus.sone.test.whenever
 import net.pterodactylus.sone.utils.asList
 import net.pterodactylus.sone.utils.asOptional
 import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException
 import net.pterodactylus.util.notify.Notification
 import net.pterodactylus.util.template.Template
@@ -42,7 +42,7 @@ import kotlin.text.Charsets.UTF_8
 /**
  * Base class for web page tests.
  */
-open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePage = { _, _ -> mock<SoneTemplatePage>() }) {
+open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePage = { _, _ -> mock() }) {
 
        val currentSone = mock<Sone>()
        val template = mock<Template>()
@@ -55,6 +55,10 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag
        val page by lazy { pageSupplier(template, webInterface) }
        val httpRequest = mock<HTTPRequest>()
        val freenetRequest = mock<FreenetRequest>()
+       init {
+               whenever(freenetRequest.l10n).thenReturn(l10n)
+               whenever(freenetRequest.uri).thenReturn(mock())
+       }
        val templateContext = TemplateContext()
        val toadletContext = deepMock<ToadletContext>()
        val responseContent = ByteArrayOutputStream()
@@ -92,8 +96,8 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag
                whenever(core.getSone(anyString())).then { allSones[it[0]] }
                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.getPostReply(anyString())).then { allPostReplies[it[0]].asOptional() }
+               whenever(core.getPost(anyString())).then { allPosts[it[0]] }
+               whenever(core.getPostReply(anyString())).then { allPostReplies[it[0]] }
                whenever(core.getReplies(anyString())).then { perPostReplies[it[0]].asList() }
                whenever(core.getAlbum(anyString())).then { allAlbums[it[0]] }
                whenever(core.getImage(anyString())).then { allImages[it[0]]}
@@ -164,7 +168,7 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag
        }
 
        fun addHttpRequestParameter(name: String, value: String) {
-               getRequestParameters[name] = getRequestParameters.getOrElse(name) { mutableListOf<String>() }.apply { add(value) }
+               getRequestParameters[name] = getRequestParameters.getOrElse(name) { mutableListOf() }.apply { add(value) }
        }
 
        fun addHttpRequestPart(name: String, value: String) {