Create base injector for all tests
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jan 2018 09:37:17 +0000 (10:37 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jan 2018 09:41:45 +0000 (10:41 +0100)
src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt

index 4c18276..da05926 100644 (file)
@@ -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()
+       )!!
+}
index 4d5d80a..45413d6 100644 (file)
@@ -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()