import java.util.Map;
+import net.pterodactylus.sone.freenet.Translation;
import net.pterodactylus.util.template.Filter;
import net.pterodactylus.util.template.TemplateContext;
-import freenet.l10n.BaseL10n;
/**
* {@link Filter} implementation that replaces a {@link Long} with a value of
- * {@code 0} by a {@link String} from an {@link BaseL10n l10n handler}.
+ * {@code 0} by a {@link String} from a {@link Translation translation}.
*/
public class UnknownDateFilter implements Filter {
- /** The l10n handler. */
- private BaseL10n l10nHandler;
+ /** The translation. */
+ private final Translation translation;
/** The key for the text to show. */
private final String unknownKey;
/**
* Creates a new unknown date filter.
*
- * @param l10nHandler
- * The l10n handler
- * @param unknownKey
- * The key of the text to show
+ * @param translation The translation
+ * @param unknownKey The key of the text to show
*/
- public UnknownDateFilter(BaseL10n l10nHandler, String unknownKey) {
- this.l10nHandler = l10nHandler;
+ public UnknownDateFilter(Translation translation, String unknownKey) {
+ this.translation = translation;
this.unknownKey = unknownKey;
}
public Object format(TemplateContext templateContext, Object data, Map<String, Object> parameters) {
if (data instanceof Long) {
if ((Long) data == 0) {
- return l10nHandler.getString(unknownKey);
+ return translation.translate(unknownKey);
}
}
return data;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.L10nFilter;
+import net.pterodactylus.sone.freenet.Translation;
import net.pterodactylus.sone.main.Loaders;
import net.pterodactylus.sone.main.PluginHomepage;
import net.pterodactylus.sone.main.PluginVersion;
import freenet.clients.http.SessionManager;
import freenet.clients.http.SessionManager.Session;
import freenet.clients.http.ToadletContext;
-import freenet.l10n.BaseL10n;
import com.codahale.metrics.*;
import com.google.common.base.Optional;
private final PageToadletRegistry pageToadletRegistry;
private final MetricRegistry metricRegistry;
+ private final Translation translation;
/** The “new Sone” notification. */
private final ListNotification<Sone> newSoneNotification;
ParserFilter parserFilter, ShortenFilter shortenFilter,
RenderFilter renderFilter,
LinkedElementRenderFilter linkedElementRenderFilter,
- PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry) {
+ PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry, Translation translation, L10nFilter l10nFilter) {
this.sonePlugin = sonePlugin;
this.loaders = loaders;
this.listNotificationFilter = listNotificationFilter;
this.linkedElementRenderFilter = linkedElementRenderFilter;
this.pageToadletRegistry = pageToadletRegistry;
this.metricRegistry = metricRegistry;
+ this.l10nFilter = l10nFilter;
+ this.translation = translation;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
soneTextParser = new SoneTextParser(getCore(), getCore());
- l10nFilter = new L10nFilter(getL10n());
this.templateContextFactory = templateContextFactory;
templateContextFactory.addTemplateObject("webInterface", this);
return listNotificationFilter.filterNotifications(notificationManager.getNotifications(), currentSone);
}
- /**
- * Returns the l10n helper of the node.
- *
- * @return The node’s l10n helper
- */
- public BaseL10n getL10n() {
- return sonePlugin.l10n().getBase();
+ public Translation getTranslation() {
+ return translation;
}
/**
import freenet.clients.http.Toadlet;
import freenet.clients.http.ToadletContext;
import freenet.clients.http.ToadletContextClosedException;
-import freenet.l10n.NodeL10n;
import freenet.support.MultiValueTable;
import freenet.support.api.HTTPRequest;
* if the toadlet context is closed
*/
public void handleMethodGET(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException {
- handleRequest(new FreenetRequest(uri, Method.GET, httpRequest, toadletContext, NodeL10n.getBase(), sessionManager));
+ handleRequest(new FreenetRequest(uri, Method.GET, httpRequest, toadletContext, sessionManager));
}
/**
* if the toadlet context is closed
*/
public void handleMethodPOST(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException {
- handleRequest(new FreenetRequest(uri, Method.POST, httpRequest, toadletContext, NodeL10n.getBase(), sessionManager));
+ handleRequest(new FreenetRequest(uri, Method.POST, httpRequest, toadletContext, sessionManager));
}
/**
bind(PluginHomepage::class.java).toInstance(PluginHomepage(sonePlugin.homepage))
bind(Database::class.java).to(MemoryDatabase::class.java).`in`(Singleton::class.java)
bind(Translation::class.java).toInstance(BaseL10nTranslation(sonePlugin.l10n().base))
- bind(BaseL10n::class.java).toInstance(sonePlugin.l10n().base)
loaders?.let { bind(Loaders::class.java).toInstance(it) }
bind(MetricRegistry::class.java).`in`(Singleton::class.java)
bind(WebOfTrustConnector::class.java).to(PluginWebOfTrustConnector::class.java).`in`(Singleton::class.java)
package net.pterodactylus.sone.web
import com.google.inject.*
-import freenet.l10n.*
import freenet.support.api.*
import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.data.*
ProfileAccessor(core)
@Provides
- fun getL10nFilter(l10n: BaseL10n) =
- L10nFilter(l10n)
+ fun getL10nFilter(translation: Translation) =
+ L10nFilter(translation)
@Provides
fun getParserFilter(core: Core, soneTextParser: SoneTextParser) =
LinkedElementsFilter(elementLoader)
@Provides
- fun getUnknownDateFilter(l10n: BaseL10n) =
- UnknownDateFilter(l10n, "View.Sone.Text.UnknownDate")
+ fun getUnknownDateFilter(translation: Translation) =
+ UnknownDateFilter(translation, "View.Sone.Text.UnknownDate")
@Provides
fun getImageLinkFilter(core: Core) =
override fun createJsonObject(request: FreenetRequest) =
createSuccessJsonObject()
- .put("value", webInterface.l10n.getString(request.parameters["key"]))
+ .put("value", webInterface.translation.translate(request.parameters["key"] ?: ""))
}
import freenet.clients.http.*
import freenet.clients.http.SessionManager.*
-import freenet.l10n.*
import freenet.support.api.*
+import net.pterodactylus.sone.freenet.*
import net.pterodactylus.util.web.*
import java.net.*
import java.util.UUID.*
open class FreenetRequest(uri: URI, method: Method,
val httpRequest: HTTPRequest,
val toadletContext: ToadletContext,
- val l10n: BaseL10n,
val sessionManager: SessionManager
) : Request(uri, method) {
package net.pterodactylus.sone.web.page
import freenet.clients.http.*
-import freenet.l10n.*
import freenet.support.api.*
import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.util.web.*
import java.net.*
-class SoneRequest(uri: URI, method: Method, httpRequest: HTTPRequest, toadletContext: ToadletContext, l10n: BaseL10n, sessionManager: SessionManager,
- val core: Core,
- val webInterface: WebInterface
-) : FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager)
+class SoneRequest(uri: URI, method: Method, httpRequest: HTTPRequest, toadletContext: ToadletContext, sessionManager: SessionManager,
+ val core: Core,
+ val webInterface: WebInterface
+) : FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager)
-fun FreenetRequest.toSoneRequest(core: Core, webInterface: WebInterface) = SoneRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager, core, webInterface)
+fun FreenetRequest.toSoneRequest(core: Core, webInterface: WebInterface) =
+ SoneRequest(uri, method, httpRequest, toadletContext, sessionManager, core, webInterface)
import freenet.clients.http.*
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.freenet.*
import net.pterodactylus.sone.main.*
import net.pterodactylus.sone.utils.*
import net.pterodactylus.sone.web.*
templateRenderer: TemplateRenderer,
private val pageTitleKey: String? = null,
private val requiresLogin: Boolean = false,
- private val pageTitle: (FreenetRequest) -> String = { pageTitleKey?.let(webInterface.l10n::getString) ?: "" }
+ private val pageTitle: (FreenetRequest) -> String = { pageTitleKey?.let(webInterface.translation::translate) ?: "" }
) : FreenetTemplatePage(templateRenderer, loaders, "noPermission.html") {
private val core = webInterface.core
private val sessionProvider: SessionProvider = webInterface
+ protected val translation: Translation = webInterface.translation
protected fun getCurrentSone(toadletContext: ToadletContext, createSession: Boolean = true) =
sessionProvider.getCurrentSone(toadletContext, createSession)
private val String.urlEncode: String get() = URLEncoder.encode(this, "UTF-8")
override fun isEnabled(toadletContext: ToadletContext) =
- isEnabled(SoneRequest(toadletContext.uri, Method.GET, HTTPRequestImpl(toadletContext.uri, "GET"), toadletContext, webInterface.l10n, webInterface.sessionManager, core, webInterface))
+ isEnabled(SoneRequest(toadletContext.uri, Method.GET, HTTPRequestImpl(toadletContext.uri, "GET"), toadletContext, webInterface.sessionManager, core, webInterface))
open fun isEnabled(soneRequest: SoneRequest) = when {
requiresLogin && getCurrentSone(soneRequest.toadletContext) == null -> false
val bytes = uploadedFile.data.use { it.toByteArray() }
val bufferedImage = bytes.toImage()
if (bufferedImage == null) {
- templateContext["messages"] = soneRequest.l10n.getString("Page.UploadImage.Error.InvalidImage")
+ templateContext["messages"] = translation.translate("Page.UploadImage.Error.InvalidImage")
return
}
override fun getPageTitle(soneRequest: SoneRequest): String =
soneRequest.parameters["sone"]!!.let(soneRequest.core::getSone)?.let { sone ->
- "${SoneAccessor.getNiceName(sone)} - ${soneRequest.l10n.getString("Page.ViewSone.Title")}"
- } ?: soneRequest.l10n.getString("Page.ViewSone.Page.TitleWithoutSone")
+ "${SoneAccessor.getNiceName(sone)} - ${translation.translate("Page.ViewSone.Title")}"
+ } ?: translation.translate("Page.ViewSone.Page.TitleWithoutSone")
}
import freenet.clients.http.SessionManager;
import freenet.clients.http.ToadletContext;
-import freenet.l10n.BaseL10n;
import freenet.support.api.HTTPRequest;
import com.google.common.base.Charsets;
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
- private final BaseL10n l10n = mock(BaseL10n.class);
private final StringWriter stringWriter = new StringWriter();
private final TemplateContext templateContext = new TemplateContext();
private Loaders loaders;
HTTPRequest httpRequest = mock(HTTPRequest.class);
ToadletContext toadletContext = mock(ToadletContext.class);
SessionManager sessionManager = mock(SessionManager.class);
- FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager);
+ FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager);
OutputStream outputStream = new ByteArrayOutputStream();
Response response = new Response(outputStream);
page.handleRequest(request, response);
import freenet.clients.http.SessionManager;
import freenet.clients.http.ToadletContext;
-import freenet.l10n.BaseL10n;
import freenet.support.api.HTTPRequest;
import org.junit.Test;
*/
public class DefaultLoadersTest {
- private final BaseL10n l10n = mock(BaseL10n.class);
private final Loaders loaders = new DefaultLoaders();
private final StringWriter stringWriter = new StringWriter();
private final TemplateContext templateContext = new TemplateContext();
HTTPRequest httpRequest = mock(HTTPRequest.class);
ToadletContext toadletContext = mock(ToadletContext.class);
SessionManager sessionManager = mock(SessionManager.class);
- FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager);
+ FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager);
OutputStream outputStream = new ByteArrayOutputStream();
Response response = new Response(outputStream);
staticPage.handleRequest(request, response);
package net.pterodactylus.sone.template
-import freenet.l10n.BaseL10n
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.test.whenever
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.equalTo
-import org.junit.Test
+import net.pterodactylus.sone.freenet.*
+import net.pterodactylus.sone.test.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
+import java.util.*
/**
* Unit test for [UnknownDateFilter].
*/
class UnknownDateFilterTest {
- private val baseL10n = mock<BaseL10n>()
+ private val translation = object : Translation {
+ override val currentLocale = Locale.ENGLISH
+ override fun translate(key: String) = if (key == unknownKey) "translated" else ""
+ }
private val unknownKey = "unknown.key"
- private val filter = UnknownDateFilter(baseL10n, unknownKey)
+ private val filter = UnknownDateFilter(translation, unknownKey)
@Test
fun `filter returns given object for non-longs`() {
- val someObject = Any()
+ val someObject = Any()
assertThat(filter.format(null, someObject, null), equalTo<Any>(someObject))
}
@Test
fun `filter returns translated value of unknown key if zero is given`() {
- whenever(baseL10n.getString(unknownKey)).thenReturn("translated")
assertThat(filter.format(null, 0L, null), equalTo<Any>("translated"))
}
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.junit.*
+import java.util.*
import kotlin.test.Test
class WebInterfaceModuleTest {
private val webInterfaceModule = WebInterfaceModule()
- private val l10n = mock<BaseL10n>()
private val loaders = mock<Loaders>()
+ private val translation = object : Translation {
+ override val currentLocale = Locale.ENGLISH
+ override fun translate(key: String) = if (key == "View.Sone.Text.UnknownDate") "unknown" else key
+ }
private val additionalModules = arrayOf(
Core::class.isProvidedByMock(),
SoneProvider::class.isProvidedByMock(),
- BaseL10n::class.isProvidedBy(l10n),
+ Translation::class.isProvidedBy(translation),
SoneTextParser::class.isProvidedByMock(),
ElementLoader::class.isProvidedByMock(),
Loaders::class.isProvidedBy(loaders),
@Test
fun `unknown date filter uses correct l10n key`() {
- whenever(l10n.getString("View.Sone.Text.UnknownDate")).thenReturn("unknown")
assertThat(getFilter("unknown")!!.format(null, 0L, emptyMap()), equalTo<Any>("unknown"))
}
import com.fasterxml.jackson.databind.ObjectMapper
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
import net.pterodactylus.sone.data.Sone.SoneStatus
import net.pterodactylus.sone.data.Sone.SoneStatus.idle
import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions
+import net.pterodactylus.sone.freenet.*
import net.pterodactylus.sone.test.deepMock
import net.pterodactylus.sone.test.get
import net.pterodactylus.sone.test.mock
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.mockito.ArgumentMatchers
-import java.util.NoSuchElementException
+import java.util.*
import javax.naming.SizeLimitExceededException
/**
val webInterface = mock<WebInterface>()
var formPassword = "form-password"
- val l10n = mock<BaseL10n>()
val core = mock<Core>()
val eventBus = mock<EventBus>()
val preferences = Preferences(eventBus)
val images = mutableMapOf<String, Image>()
val translations = mutableMapOf<String, String>()
+ private val translation = object : Translation {
+ override val currentLocale = Locale.ENGLISH
+ override fun translate(key: String) = translations[key] ?: ""
+ }
+
init {
whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory())
whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext), ArgumentMatchers.anyBoolean())).thenReturn(currentSone)
whenever(webInterface.getNotification(ArgumentMatchers.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)
-
- whenever(l10n.getString(ArgumentMatchers.anyString())).then { translations[it[0]] }
+ whenever(webInterface.translation).thenReturn(translation)
whenever(core.preferences).thenReturn(preferences)
whenever(core.updateChecker).thenReturn(updateChecker)
import freenet.clients.http.*
import freenet.clients.http.SessionManager.*
-import freenet.l10n.*
import freenet.support.api.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.util.web.*
private val method = Method.GET
private val httpRequest = mock(HTTPRequest::class.java)
private val toadletContext = mock(ToadletContext::class.java)
- private val l10n = mock<BaseL10n>()
private val sessionManager = mock<SessionManager>()
- private val request = FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager)
+ private val request = FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager)
@Test
fun `uri is retained correctly`() {
}
@Test
- fun `l10n is retained correctly`() {
- assertThat(request.l10n, equalTo(l10n))
- }
-
- @Test
fun `null is returned if no session exists`() {
assertThat(request.existingSession, nullValue())
}
private val method = Method.GET
private val httpRequest = Mockito.mock(HTTPRequest::class.java)
private val toadletContext = Mockito.mock(ToadletContext::class.java)
- private val l10n = mock<BaseL10n>()
private val sessionManager = mock<SessionManager>()
private val core = mock<Core>()
private val webInterface = mock<WebInterface>()
- private val soneRequest = SoneRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager, core, webInterface)
+ private val soneRequest = SoneRequest(uri, method, httpRequest, toadletContext, sessionManager, core, webInterface)
@Test
fun `freenet request properties are retained correctly`() {
assertThat(soneRequest.method, equalTo(method))
assertThat(soneRequest.httpRequest, equalTo(httpRequest))
assertThat(soneRequest.toadletContext, equalTo(toadletContext))
- assertThat(soneRequest.l10n, equalTo(l10n))
assertThat(soneRequest.sessionManager, equalTo(sessionManager))
}
@Test
fun `freenet request is wrapped correctly`() {
- val freenetRequest = FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager)
+ val freenetRequest = FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager)
val wrappedSoneRequest = freenetRequest.toSoneRequest(core, webInterface)
assertThat(wrappedSoneRequest.uri, equalTo(uri))
assertThat(wrappedSoneRequest.method, equalTo(method))
assertThat(wrappedSoneRequest.httpRequest, equalTo(httpRequest))
assertThat(wrappedSoneRequest.toadletContext, equalTo(toadletContext))
- assertThat(wrappedSoneRequest.l10n, equalTo(l10n))
assertThat(wrappedSoneRequest.sessionManager, equalTo(sessionManager))
assertThat(wrappedSoneRequest.core, sameInstance(core))
assertThat(wrappedSoneRequest.webInterface, sameInstance(webInterface))
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.DeleteSone.Title")).thenReturn("delete sone page")
+ addTranslation("Page.DeleteSone.Title", "delete sone page")
assertThat(page.getPageTitle(soneRequest), equalTo("delete sone page"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.DismissNotification.Title")).thenReturn("dismiss notification page")
+ addTranslation("Page.DismissNotification.Title", "dismiss notification page")
assertThat(page.getPageTitle(soneRequest), equalTo("dismiss notification page"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.Distrust.Title")).thenReturn("distrust page title")
+ addTranslation("Page.Distrust.Title", "distrust page title")
assertThat(page.getPageTitle(soneRequest), equalTo("distrust page title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.EditAlbum.Title")).thenReturn("edit album page")
+ addTranslation("Page.EditAlbum.Title", "edit album page")
assertThat(page.getPageTitle(soneRequest), equalTo("edit album page"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.EditImage.Title")).thenReturn("edit image page title")
+ addTranslation("Page.EditImage.Title", "edit image page title")
assertThat(page.getPageTitle(soneRequest), equalTo("edit image page title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.EditProfileField.Title")).thenReturn("edit profile field title")
+ addTranslation("Page.EditProfileField.Title", "edit profile field title")
assertThat(page.getPageTitle(soneRequest), equalTo("edit profile field title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.EditProfile.Title")).thenReturn("edit profile page title")
+ addTranslation("Page.EditProfile.Title", "edit profile page title")
assertThat(page.getPageTitle(soneRequest), equalTo("edit profile page title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.FollowSone.Title")).thenReturn("follow sone page title")
+ addTranslation("Page.FollowSone.Title", "follow sone page title")
assertThat(page.getPageTitle(soneRequest), equalTo("follow sone page title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.ImageBrowser.Title")).thenReturn("image browser page title")
+ addTranslation("Page.ImageBrowser.Title", "image browser page title")
assertThat(page.getPageTitle(soneRequest), equalTo("image browser page title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.Index.Title")).thenReturn("index page title")
+ addTranslation("Page.Index.Title", "index page title")
assertThat(page.getPageTitle(soneRequest), equalTo("index page title"))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.KnownSones.Title")).thenReturn("known sones page title")
+ addTranslation("Page.KnownSones.Title", "known sones page title")
assertThat(page.getPageTitle(soneRequest), equalTo("known sones page title"))
}
@Test
fun `page title is retrieved from l10n if page title key is given`() {
SoneTemplatePage(webInterface, loaders, templateRenderer, pageTitleKey = "page.title", requiresLogin = false).let { page ->
- whenever(l10n.getString("page.title")).thenReturn("Page Title")
+ addTranslation("page.title", "Page Title")
assertThat(page.getPageTitle(soneRequest), equalTo("Page Title"))
}
}
import freenet.support.api.*
import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.freenet.*
import net.pterodactylus.sone.freenet.wot.*
import net.pterodactylus.sone.main.*
import net.pterodactylus.sone.test.deepMock
import java.io.*
import java.net.*
import java.nio.charset.*
+import java.util.*
import kotlin.text.Charsets.UTF_8
/**
val core = webInterface.core
val eventBus = mock<EventBus>()
val preferences = Preferences(eventBus)
- val l10n = webInterface.l10n!!
val sessionManager = mock<SessionManager>()
open val page by lazy { pageSupplier(webInterface, loaders, templateRenderer) }
val freenetRequest = mock<FreenetRequest>()
init {
- whenever(freenetRequest.l10n).thenReturn(l10n)
whenever(freenetRequest.sessionManager).thenReturn(sessionManager)
whenever(freenetRequest.uri).thenReturn(mock())
}
private val notifications = mutableMapOf<String, Notification>()
private val translations = mutableMapOf<String, String>()
+ private val translation = object : Translation {
+ override val currentLocale = Locale.ENGLISH
+ override fun translate(key: String) = translations[key] ?: key
+ }
+
init {
setupCore()
setupWebInterface()
setupHttpRequest()
setupFreenetRequest()
- setupTranslations()
}
private fun setupCore() {
whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)
whenever(webInterface.getNotifications(currentSone)).then { notifications.values }
whenever(webInterface.getNotification(anyString())).then { notifications[it[0]].asOptional() }
+ whenever(webInterface.translation).thenReturn(translation)
}
private fun setupHttpRequest() {
whenever(freenetRequest.toadletContext).thenReturn(toadletContext)
}
- private fun setupTranslations() {
- whenever(l10n.getString(anyString())).then { translations[it[0]] ?: it[0] }
- }
-
fun setMethod(method: Method) {
whenever(httpRequest.method).thenReturn(method.name)
whenever(freenetRequest.method).thenReturn(method)