From: David ‘Bombe’ Roden Date: Sun, 21 Jan 2018 10:33:12 +0000 (+0100) Subject: Add test for DI constructability of SearchPage X-Git-Tag: v79^2~197 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=f006d66e2b479a97fe476c1eb9cad5b6421f60aa Add test for DI constructability of SearchPage --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt index 7cddc35..e94d879 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt @@ -22,14 +22,18 @@ import net.pterodactylus.util.template.TemplateContext import net.pterodactylus.util.text.StringEscaper import net.pterodactylus.util.text.TextException import java.util.concurrent.TimeUnit.MINUTES +import javax.inject.Inject /** * This page lets the user search for posts and replies that contain certain * words. */ -class SearchPage @JvmOverloads constructor(template: Template, webInterface: WebInterface, ticker: Ticker = Ticker.systemTicker()): +class SearchPage(template: Template, webInterface: WebInterface, ticker: Ticker = Ticker.systemTicker()) : SoneTemplatePage("search.html", webInterface, template, "Page.Search.Title") { + @Inject constructor(template: Template, webInterface: WebInterface) : + this(template, webInterface, Ticker.systemTicker()) + private val cache: Cache, Pagination> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build() override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt index 94af5da..104006c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt @@ -8,13 +8,16 @@ import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.data.Profile import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.test.getInstance import net.pterodactylus.sone.test.isOnPage import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.utils.asOptional +import net.pterodactylus.sone.web.baseInjector import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.notNullValue import org.junit.Test import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicInteger @@ -364,4 +367,9 @@ class SearchPageTest: WebPageTest({ template, webInterface -> SearchPage(templat @Suppress("UNCHECKED_CAST") private operator fun get(key: String): T? = templateContext[key] as? T + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + }