From: David ‘Bombe’ Roden Date: Sat, 20 Jan 2018 09:23:48 +0000 (+0100) Subject: Begin collection all pages in a dependency injection-friendly container X-Git-Tag: v79^2~234 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=035b8512e0b72d2e81d303992e877bd2abd172a0;p=Sone.git Begin collection all pages in a dependency injection-friendly container --- diff --git a/src/main/java/net/pterodactylus/sone/web/AllPages.kt b/src/main/java/net/pterodactylus/sone/web/AllPages.kt new file mode 100644 index 0000000..c2973ac --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/AllPages.kt @@ -0,0 +1,14 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.sone.web.pages.AboutPage +import javax.inject.Inject + +/** + * Container for all web pages. This uses field injection because there are way too many pages + * to sensibly use constructor injection. + */ +class AllPages { + + @Inject lateinit var aboutPage: AboutPage + +} diff --git a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt new file mode 100644 index 0000000..4c18276 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt @@ -0,0 +1,35 @@ +package net.pterodactylus.sone.web + +import com.google.inject.Guice +import net.pterodactylus.sone.main.SonePlugin.PluginHomepage +import net.pterodactylus.sone.main.SonePlugin.PluginVersion +import net.pterodactylus.sone.main.SonePlugin.PluginYear +import net.pterodactylus.sone.test.getInstance +import net.pterodactylus.sone.test.isProvidedByMock +import net.pterodactylus.util.template.Template +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.notNullValue +import org.junit.Test + +/** + * Test for [AllPages]. + */ +class AllPagesTest { + + private val injector by lazy { + Guice.createInjector( + Template::class.isProvidedByMock(), + WebInterface::class.isProvidedByMock(), + PluginVersion::class.isProvidedByMock(), + PluginYear::class.isProvidedByMock(), + PluginHomepage::class.isProvidedByMock() + )!! + } + private val allPages by lazy { injector.getInstance() } + + @Test + fun `about page can be injected`() { + assertThat(allPages.aboutPage, notNullValue()) + } + +}