From 811b050899f1ac9e61d9cf724f67d59c8f7bac36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 20 Jan 2018 10:37:17 +0100 Subject: [PATCH] Create base injector for all tests --- src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt | 13 +++++++++---- .../net/pterodactylus/sone/web/pages/AboutPageTest.kt | 8 ++------ 2 files changed, 11 insertions(+), 10 deletions(-) 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() -- 2.7.4