From: David ‘Bombe’ Roden Date: Sun, 5 Feb 2017 17:19:16 +0000 (+0100) Subject: Remove dependency injection configuration from the classes X-Git-Tag: 0.9.7^2~307 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b0e986537b3c2a4992bb28eee8682d1a0207b01a;p=Sone.git Remove dependency injection configuration from the classes It will be managed in a bunch of upcoming modules. --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/AboutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/AboutPage.kt index 6206d31..da60e98 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/AboutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/AboutPage.kt @@ -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 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt index 9227971..47b0d04 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt @@ -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) { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/AboutPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/AboutPageTest.kt index 0e8e6b3..d4adf3a 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/AboutPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/AboutPageTest.kt @@ -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(year)) } - @Test - fun `page can be created by guice`() { - assertThat(childInjector.getInstance(), notNullValue()) - } - - @Test - fun `page is created as singleton`() { - val firstInstance = childInjector.getInstance() - val secondInstance = childInjector.getInstance() - assertThat(firstInstance, sameInstance(secondInstance)) - } - } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt index bbbe6ef..bebe10c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt @@ -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(), notNullValue()) - } - - @Test - fun `bookmark page is created as singleton`() { - val firstInstance = injector.getInstance() - val secondInstance = injector.getInstance() - assertThat(firstInstance, sameInstance(secondInstance)) - } - }