From: David ‘Bombe’ Roden Date: Thu, 25 Jan 2018 17:52:27 +0000 (+0100) Subject: Add test for DI constructability of GetLinkedElementAjaxPage X-Git-Tag: v79^2~171 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=aefada2a6f469577c522c54b23d00ee735daa019;p=Sone.git Add test for DI constructability of GetLinkedElementAjaxPage --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt index 809abdc..760c1de 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt @@ -9,11 +9,12 @@ import net.pterodactylus.sone.utils.jsonArray import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest +import javax.inject.Inject /** * Renders linked elements after they have been loaded. */ -class GetLinkedElementAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val linkedElementRenderFilter: LinkedElementRenderFilter): +class GetLinkedElementAjaxPage @Inject constructor(webInterface: WebInterface, private val elementLoader: ElementLoader, private val linkedElementRenderFilter: LinkedElementRenderFilter): JsonPage("getLinkedElement.ajax", webInterface) { override val needsFormPassword = false diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPageTest.kt index dee8cd6..fb8b527 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPageTest.kt @@ -1,14 +1,19 @@ package net.pterodactylus.sone.web.ajax import com.fasterxml.jackson.databind.JsonNode +import net.pterodactylus.sone.core.ElementLoader import net.pterodactylus.sone.core.LinkedElement import net.pterodactylus.sone.template.LinkedElementRenderFilter +import net.pterodactylus.sone.test.getInstance +import net.pterodactylus.sone.test.isProvidedByMock import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.utils.jsonArray +import net.pterodactylus.sone.web.baseInjector import net.pterodactylus.util.template.TemplateContext import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers +import org.hamcrest.Matchers.notNullValue import org.junit.Test import org.mockito.ArgumentMatchers @@ -39,6 +44,14 @@ class GetLinkedElementAjaxPageTest: JsonPageTest("getLinkedElement.ajax", requir )) } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.createChildInjector( + ElementLoader::class.isProvidedByMock(), + LinkedElementRenderFilter::class.isProvidedByMock() + ).getInstance(), notNullValue()) + } + private fun JsonNode.toMap() = fields().asSequence().map { it.key!! to if (it.value.isNull) null else it.value.asText()!! }.toMap() }