From fd852f7aee78ea04fb49920e698500c71321c6d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 25 Jan 2018 19:14:59 +0100 Subject: [PATCH] Add test for DI constructability of GetTimesAjaxPage --- .../net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt | 3 ++- .../pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt index cb3b86d..233cf75 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt @@ -8,11 +8,12 @@ import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import java.text.SimpleDateFormat import java.util.TimeZone +import javax.inject.Inject /** * Ajax page that returns a formatted, relative timestamp for replies or posts. */ -class GetTimesAjaxPage(webInterface: WebInterface, +class GetTimesAjaxPage @Inject constructor(webInterface: WebInterface, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone) : JsonPage("getTimes.ajax", webInterface) { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt index d6b5aa0..62a34d1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt @@ -6,18 +6,23 @@ import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.freenet.L10nFilter import net.pterodactylus.sone.freenet.L10nText import net.pterodactylus.sone.test.get +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.text.TimeText import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.sone.utils.jsonObject +import net.pterodactylus.sone.web.baseInjector import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsInAnyOrder import org.hamcrest.Matchers.emptyIterable +import org.hamcrest.Matchers.notNullValue import org.junit.Before import org.junit.Test import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyLong +import java.util.TimeZone import java.util.TimeZone.getTimeZone /** @@ -106,4 +111,13 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f )) } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.createChildInjector( + TimeTextConverter::class.isProvidedByMock(), + L10nFilter::class.isProvidedByMock(), + TimeZone::class.isProvidedByMock() + ).getInstance(), notNullValue()) + } + } -- 2.7.4