Add test for DI constructability of AboutPage
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jan 2018 09:07:51 +0000 (10:07 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jan 2018 09:41:44 +0000 (10:41 +0100)
src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt

index 148f10e..29d941e 100644 (file)
@@ -7,11 +7,12 @@ import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.util.template.Template
 import net.pterodactylus.util.template.TemplateContext
+import javax.inject.Inject
 
 /**
  * A [SoneTemplatePage] that stores information about Sone in the [TemplateContext].
  */
-class AboutPage(template: Template, webInterface: WebInterface,
+class AboutPage @Inject constructor(template: Template, webInterface: WebInterface,
                private val pluginVersion: PluginVersion,
                private val pluginYear: PluginYear,
                private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, template, "Page.About.Title") {
index 142bf81..7856ee2 100644 (file)
@@ -1,10 +1,16 @@
 package net.pterodactylus.sone.web.pages
 
+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.sone.web.WebInterface
+import net.pterodactylus.util.template.Template
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Test
 
 /**
@@ -46,4 +52,16 @@ class AboutPageTest: WebPageTest({ template, webInterface -> AboutPage(template,
                assertThat(templateContext["year"], equalTo<Any>(year))
        }
 
+       @Test
+       fun `about page can be created by dependency injection`() {
+               val injector = Guice.createInjector(
+                               Template::class.isProvidedByMock(),
+                               WebInterface::class.isProvidedByMock(),
+                               PluginVersion::class.isProvidedByMock(),
+                               PluginYear::class.isProvidedByMock(),
+                               PluginHomepage::class.isProvidedByMock()
+               )
+               assertThat(injector.getInstance<AboutPage>(), notNullValue())
+       }
+
 }