package net.pterodactylus.sone.web;
+import static net.pterodactylus.sone.test.GuiceKt.supply;
import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
import com.google.common.collect.Multimap;
import com.google.common.eventbus.EventBus;
import com.google.common.io.ByteStreams;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
protected final List<Sone> localSones = new ArrayList<>();
private final ListMultimap<String, PostReply> postReplies = ArrayListMultimap.create();
+ protected final Injector injector = Guice.createInjector(
+ supply(WebInterface.class).byInstance(webInterface),
+ supply(Template.class).byInstance(template)
+ );
+
protected WebPageTest() {
try {
responseInputStream = new PipedInputStream(responseOutputStream);
package net.pterodactylus.sone.web
-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.util.template.Template
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.notNullValue
private val year = 1234
private val homepage = "home://page"
private val page = AboutPage(template, webInterface, PluginVersion(version), PluginYear(year), PluginHomepage(homepage))
- private val injector = Guice.createInjector(
- Template::class.isProvidedByMock(),
- WebInterface::class.isProvidedByMock(),
+ private val childInjector = injector.createChildInjector(
PluginVersion::class.isProvidedByMock(),
PluginYear::class.isProvidedByMock(),
PluginHomepage::class.isProvidedByMock()
@Test
fun `page can be created by guice`() {
- assertThat(injector.getInstance<AboutPage>(), notNullValue())
+ assertThat(childInjector.getInstance<AboutPage>(), notNullValue())
}
@Test
fun `page is created as singleton`() {
- val firstInstance = injector.getInstance<AboutPage>()
- val secondInstance = injector.getInstance<AboutPage>()
+ val firstInstance = childInjector.getInstance<AboutPage>()
+ val secondInstance = childInjector.getInstance<AboutPage>()
assertThat(firstInstance, sameInstance(secondInstance))
}