Begin collection all pages in a dependency injection-friendly container
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jan 2018 09:23:48 +0000 (10:23 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jan 2018 09:41:45 +0000 (10:41 +0100)
src/main/java/net/pterodactylus/sone/web/AllPages.kt [new file with mode: 0644]
src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt [new file with mode: 0644]

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 (file)
index 0000000..c2973ac
--- /dev/null
@@ -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 (file)
index 0000000..4c18276
--- /dev/null
@@ -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<AllPages>() }
+
+       @Test
+       fun `about page can be injected`() {
+               assertThat(allPages.aboutPage, notNullValue())
+       }
+
+}