X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebPageTest.java;h=2bd2680b3d809816feedea140e611bbda75ac692;hb=9c61b749711a041a40a5370c17fdaa23c10e7696;hp=d8b9462b3db794a0acc7dcde1d2c22ad9fb6a9d4;hpb=c2c776f038ec312447ab64504efa88b1f3533b9a;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/web/WebPageTest.java b/src/test/java/net/pterodactylus/sone/web/WebPageTest.java index d8b9462..2bd2680 100644 --- a/src/test/java/net/pterodactylus/sone/web/WebPageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/WebPageTest.java @@ -1,5 +1,6 @@ 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; @@ -60,6 +61,8 @@ import com.google.common.collect.ListMultimap; 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; @@ -103,6 +106,11 @@ public abstract class WebPageTest { protected final List localSones = new ArrayList<>(); private final ListMultimap 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); @@ -156,6 +164,13 @@ public abstract class WebPageTest { return requestParameters.containsKey(parameter) ? requestParameters.get(parameter).iterator().next() : invocation.getArgument(1); } }); + when(httpRequest.isParameterSet(anyString())).thenAnswer(new Answer() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + return requestParameters.containsKey(invocation.getArgument(0)) && + requestParameters.get(invocation.getArgument(0)).iterator().next() != null; + } + }); when(httpRequest.isPartSet(anyString())).thenAnswer(new Answer() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { @@ -257,8 +272,8 @@ public abstract class WebPageTest { @Before public final void setupWebInterface() { - when(webInterface.getCurrentSone(toadletContext)).thenReturn(currentSone); - when(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone); + when(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone); + when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone); when(webInterface.getNotification(anyString())).thenReturn(Optional.absent()); when(webInterface.getNotifications(currentSone)).thenReturn(new ArrayList()); } @@ -273,8 +288,8 @@ public abstract class WebPageTest { } protected void unsetCurrentSone() { - when(webInterface.getCurrentSone(toadletContext)).thenReturn(null); - when(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(null); + when(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(null); + when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null); } protected void request(String uri, Method method) { @@ -355,7 +370,7 @@ public abstract class WebPageTest { getPage().handleRequest(freenetRequest, templateContext); } - protected void verifyRedirect(String target, Runnable verification) throws RedirectException { + protected void verifyRedirect(String target, Runnable verification) throws RedirectException { expectedException.expect(redirectsTo(target)); try { getPage().handleRequest(freenetRequest, templateContext);