X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FWebPageTest.kt;h=5c842df4e41472253ae53ef102ea434753db3917;hp=4f72902060051dd639ccea20f3e71b45d7f0ebb0;hb=125dab18d4412f547334f4fa2b27e5f7676eec5c;hpb=03c29a3838e23ed0b9731ca4d84cf58038c30dfe diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt index 4f72902..5c842df 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt @@ -1,7 +1,7 @@ package net.pterodactylus.sone.web.pages import com.google.common.eventbus.EventBus -import freenet.clients.http.ToadletContext +import freenet.clients.http.* import freenet.support.SimpleReadOnlyArrayBucket import freenet.support.api.HTTPRequest import freenet.support.api.HTTPUploadedFile @@ -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 @@ -51,10 +51,19 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag val eventBus = mock() val preferences = Preferences(eventBus) val l10n = webInterface.l10n!! + val sessionManager = mock() val page by lazy { pageSupplier(template, webInterface) } + val SoneTemplatePage.menuName get() = javaClass.getAnnotation(MenuName::class.java)?.value + val httpRequest = mock() val freenetRequest = mock() + init { + whenever(freenetRequest.l10n).thenReturn(l10n) + whenever(freenetRequest.sessionManager).thenReturn(sessionManager) + whenever(freenetRequest.uri).thenReturn(mock()) + } + val soneRequest by lazy { freenetRequest.toSoneRequest(core, webInterface) } val templateContext = TemplateContext() val toadletContext = deepMock() val responseContent = ByteArrayOutputStream() @@ -102,6 +111,7 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag } private fun setupWebInterface() { + whenever(webInterface.sessionManager).thenReturn(sessionManager) whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone) whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone) whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)