From aefada2a6f469577c522c54b23d00ee735daa019 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 25 Jan 2018 18:52:27 +0100 Subject: [PATCH] Add test for DI constructability of GetLinkedElementAjaxPage --- .../pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt | 3 ++- .../sone/web/ajax/GetLinkedElementAjaxPageTest.kt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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() } -- 2.7.4