From 035b8512e0b72d2e81d303992e877bd2abd172a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 20 Jan 2018 10:23:48 +0100 Subject: [PATCH] Begin collection all pages in a dependency injection-friendly container --- .../java/net/pterodactylus/sone/web/AllPages.kt | 14 +++++++++ .../net/pterodactylus/sone/web/AllPagesTest.kt | 35 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/web/AllPages.kt create mode 100644 src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt 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()) + } + +} -- 2.7.4