Remove dependency injection configuration from the classes
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 5 Feb 2017 17:19:16 +0000 (18:19 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 5 Feb 2017 17:19:16 +0000 (18:19 +0100)
It will be managed in a bunch of upcoming modules.

src/main/kotlin/net/pterodactylus/sone/web/AboutPage.kt
src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt
src/test/kotlin/net/pterodactylus/sone/web/AboutPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt

index 6206d31..da60e98 100644 (file)
@@ -6,17 +6,14 @@ import net.pterodactylus.sone.main.SonePlugin.PluginYear
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.util.template.Template
 import net.pterodactylus.util.template.TemplateContext
-import javax.inject.Inject
-import javax.inject.Singleton
 
 /**
  * A [SoneTemplatePage] that stores information about Sone in the [TemplateContext].
  */
-@Singleton
-class AboutPage @Inject constructor(template: Template, webInterface: WebInterface,
-                                    private val pluginVersion: PluginVersion,
-                                    private val pluginYear: PluginYear,
-                                    private val pluginHomepage: PluginHomepage) : SoneTemplatePage("about.html", template, "Page.About.Title", webInterface, false) {
+class AboutPage(template: Template, webInterface: WebInterface,
+               private val pluginVersion: PluginVersion,
+               private val pluginYear: PluginYear,
+               private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", template, "Page.About.Title", webInterface, false) {
 
        override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
                templateContext["version"] = pluginVersion.version
index 9227971..47b0d04 100644 (file)
@@ -10,8 +10,7 @@ import javax.inject.Singleton
 /**
  * Page that lets the user bookmark a post.
  */
-@Singleton
-class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface)
+class BookmarkPage(template: Template, webInterface: WebInterface)
        : SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) {
 
        override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
index 0e8e6b3..d4adf3a 100644 (file)
@@ -3,28 +3,19 @@ package net.pterodactylus.sone.web
 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 org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.hamcrest.Matchers.sameInstance
 import org.junit.Test
 
 /**
  * Unit test for [AboutPage].
  */
-class AboutPageTest : WebPageTest() {
+class AboutPageTest: WebPageTest() {
 
        private val version = "0.1.2"
        private val year = 1234
        private val homepage = "home://page"
        private val page = AboutPage(template, webInterface, PluginVersion(version), PluginYear(year), PluginHomepage(homepage))
-       private val childInjector = injector.createChildInjector(
-                       PluginVersion::class.isProvidedByMock(),
-                       PluginYear::class.isProvidedByMock(),
-                       PluginHomepage::class.isProvidedByMock()
-       )!!
 
        @Test
        fun `page returns correct path`() {
@@ -54,16 +45,4 @@ class AboutPageTest : WebPageTest() {
                assertThat(templateContext["year"], equalTo<Any>(year))
        }
 
-       @Test
-       fun `page can be created by guice`() {
-               assertThat(childInjector.getInstance<AboutPage>(), notNullValue())
-       }
-
-       @Test
-       fun `page is created as singleton`() {
-           val firstInstance = childInjector.getInstance<AboutPage>()
-               val secondInstance = childInjector.getInstance<AboutPage>()
-               assertThat(firstInstance, sameInstance(secondInstance))
-       }
-
 }
index bbbe6ef..bebe10c 100644 (file)
@@ -1,14 +1,10 @@
 package net.pterodactylus.sone.web
 
-import com.google.inject.Guice
 import net.pterodactylus.sone.data.Post
-import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.util.web.Method.POST
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.hamcrest.Matchers.sameInstance
 import org.junit.Test
 import org.mockito.ArgumentMatchers.any
 import org.mockito.Mockito.never
@@ -57,16 +53,4 @@ class BookmarkPageTest : WebPageTest() {
                }
        }
 
-       @Test
-       fun `bookmark page can be created by guice`() {
-               assertThat(injector.getInstance<BookmarkPage>(), notNullValue())
-       }
-
-       @Test
-       fun `bookmark page is created as singleton`() {
-               val firstInstance = injector.getInstance<BookmarkPage>()
-               val secondInstance = injector.getInstance<BookmarkPage>()
-               assertThat(firstInstance, sameInstance(secondInstance))
-       }
-
 }