Add test for DI constructability of OptionsPage
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 21 Jan 2018 10:23:05 +0000 (11:23 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 21 Jan 2018 10:23:05 +0000 (11:23 +0100)
src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt

index 5205457..31a65c1 100644 (file)
@@ -10,11 +10,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
 
 /**
  * This page lets the user edit the options of the Sone plugin.
  */
-class OptionsPage(template: Template, webInterface: WebInterface):
+class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface):
                SoneTemplatePage("options.html", webInterface, template, "Page.Options.Title") {
 
        override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
index 4e4c02e..94ae905 100644 (file)
@@ -6,11 +6,14 @@ import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent.TRUSTED
 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS
 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO
 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING
+import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.web.baseInjector
 import net.pterodactylus.util.web.Method.POST
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
 import org.hamcrest.Matchers.hasItem
+import org.hamcrest.Matchers.notNullValue
 import org.hamcrest.Matchers.nullValue
 import org.junit.Before
 import org.junit.Test
@@ -376,4 +379,9 @@ class OptionsPageTest: WebPageTest(::OptionsPage) {
                verifyThatPreferencesCanBeSet("trust-comment", "", "Set from Sone Web Interface") { core.preferences.trustComment }
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+           assertThat(baseInjector.getInstance<OptionsPage>(), notNullValue())
+       }
+
 }