From: David ‘Bombe’ Roden Date: Sat, 20 Jan 2018 09:37:17 +0000 (+0100) Subject: Create base injector for all tests X-Git-Tag: v79^2~233 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=811b050899f1ac9e61d9cf724f67d59c8f7bac36;p=Sone.git Create base injector for all tests --- diff --git a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt index 4c18276..da05926 100644 --- a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt +++ b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt @@ -1,6 +1,6 @@ package net.pterodactylus.sone.web -import com.google.inject.Guice +import com.google.inject.Guice.createInjector import net.pterodactylus.sone.main.SonePlugin.PluginHomepage import net.pterodactylus.sone.main.SonePlugin.PluginVersion import net.pterodactylus.sone.main.SonePlugin.PluginYear @@ -17,9 +17,7 @@ import org.junit.Test class AllPagesTest { private val injector by lazy { - Guice.createInjector( - Template::class.isProvidedByMock(), - WebInterface::class.isProvidedByMock(), + baseInjector.createChildInjector( PluginVersion::class.isProvidedByMock(), PluginYear::class.isProvidedByMock(), PluginHomepage::class.isProvidedByMock() @@ -33,3 +31,10 @@ class AllPagesTest { } } + +val baseInjector by lazy { + createInjector( + Template::class.isProvidedByMock(), + WebInterface::class.isProvidedByMock() + )!! +} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt index 4d5d80a..45413d6 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt @@ -1,13 +1,11 @@ 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 net.pterodactylus.sone.web.baseInjector import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.notNullValue @@ -54,9 +52,7 @@ class AboutPageTest : WebPageTest({ template, webInterface -> AboutPage(template @Test fun `about page can be created by dependency injection`() { - val injector = Guice.createInjector( - Template::class.isProvidedByMock(), - WebInterface::class.isProvidedByMock(), + val injector = baseInjector.createChildInjector( PluginVersion::class.isProvidedByMock(), PluginYear::class.isProvidedByMock(), PluginHomepage::class.isProvidedByMock()