X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FTestObjects.kt;h=ffd6f15b7aed7c60c2af23db538ee435c3dccaf8;hp=a7e0a8a1184011d0f718d9f5273476f41d9779c6;hb=HEAD;hpb=f339996e95e45359e14becbe62d49863cf26acfd diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt index a7e0a8a..ffd6f15 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt @@ -1,8 +1,8 @@ package net.pterodactylus.sone.web.ajax +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 @@ -19,6 +19,7 @@ import net.pterodactylus.sone.data.Sone 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 @@ -31,7 +32,7 @@ import net.pterodactylus.util.template.TemplateContextFactory 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 /** @@ -39,9 +40,10 @@ import javax.naming.SizeLimitExceededException */ open class TestObjects { + val objectMapper = ObjectMapper() + val webInterface = mock() var formPassword = "form-password" - val l10n = mock() val core = mock() val eventBus = mock() val preferences = Preferences(eventBus) @@ -71,29 +73,30 @@ open class TestObjects { val images = mutableMapOf() val translations = mutableMapOf() + 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.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone) - whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone) + whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(currentSone) whenever(webInterface.core).thenReturn(core) whenever(webInterface.formPassword).then { formPassword } whenever(webInterface.getNotifications(currentSone)).thenAnswer { notifications.values } 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) - whenever(core.getSone(ArgumentMatchers.anyString())).thenAnswer { (localSones + remoteSones)[it.getArgument(0)].asOptional() } + whenever(core.getSone(ArgumentMatchers.anyString())).thenAnswer { (localSones + remoteSones)[it.getArgument(0)] } whenever(core.getLocalSone(ArgumentMatchers.anyString())).thenAnswer { localSones[it[0]] } - whenever(core.getPost(ArgumentMatchers.anyString())).thenAnswer { (posts + newPosts)[it[0]].asOptional() } + whenever(core.getPost(ArgumentMatchers.anyString())).thenAnswer { (posts + newPosts)[it[0]] } whenever(core.getLikes(ArgumentMatchers.any())).then { postLikes[it[0]] ?: emptySet() } whenever(core.getLikes(ArgumentMatchers.any())).then { replyLikes[it[0]] ?: emptySet() } - whenever(core.getPostReply(ArgumentMatchers.anyString())).then { replies[it[0]].asOptional() } + whenever(core.getPostReply(ArgumentMatchers.anyString())).then { replies[it[0]] } whenever(core.getAlbum(ArgumentMatchers.anyString())).then { albums[it[0]] } whenever(core.getImage(ArgumentMatchers.anyString())).then { images[it[0]] } whenever(core.getImage(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean())).then { images[it[0]] } @@ -134,9 +137,7 @@ open class TestObjects { } protected fun unsetCurrentSone() { - whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext), ArgumentMatchers.anyBoolean())).thenReturn(null) - whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null) - whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(null) + whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(null) } protected fun postRequest() {