X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonPageTest.kt;h=c950a3121c5425b85ce47ae7a045e89396a5550d;hp=ac70936c5d6ccb1c05433d6c923afc91c4bf6299;hb=37e7a7dbf3be9bdcbdcfaa7fd783cf4a1632d57f;hpb=e194b91c7053152c9c5503f8882e1ddefcd23bdc diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt index ac70936..c950a31 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.ajax import com.google.common.eventbus.EventBus import freenet.clients.http.ToadletContext +import freenet.l10n.BaseL10n import freenet.support.SimpleReadOnlyArrayBucket import freenet.support.api.HTTPRequest import net.pterodactylus.sone.core.Core @@ -26,6 +27,7 @@ import net.pterodactylus.sone.utils.asOptional import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.notify.Notification +import net.pterodactylus.util.template.TemplateContextFactory import net.pterodactylus.util.web.Method.GET import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -50,6 +52,7 @@ abstract class JsonPageTest( pageSupplier: (WebInterface) -> JsonPage = { _ -> mock() }) { protected val webInterface = mock() + protected val l10n = mock() protected val core = mock() protected val eventBus = mock() protected val preferences = Preferences(eventBus) @@ -79,9 +82,11 @@ abstract class JsonPageTest( private val notifications = mutableMapOf() private val albums = mutableMapOf() private val images = mutableMapOf() + private val translations = mutableMapOf() @Before fun setupWebInterface() { + whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory()) whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone) whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone) whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone) @@ -90,6 +95,12 @@ abstract class JsonPageTest( whenever(webInterface.getNotification(anyString())).then { notifications[it[0]].asOptional() } whenever(webInterface.getNewPosts(currentSone)).thenAnswer { newPosts.values } whenever(webInterface.getNewReplies(currentSone)).thenAnswer { newReplies.values } + whenever(webInterface.l10n).thenReturn(l10n) + } + + @Before + fun setupTranslations() { + whenever(l10n.getString(anyString())).then { translations[it[0]] } } @Before @@ -239,6 +250,10 @@ abstract class JsonPageTest( images[imageId ?: image.id] = image } + protected fun addTranslation(key: String, value: String) { + translations[key] = value + } + @Test fun `page returns correct path`() { assertThat(page.path, equalTo(expectedPath))