X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FWebPageTest.java;h=97749154d815abf8a42422cd77e2f5581f784fe7;hp=f4936b7553bfc5247d2f608c570df8dfec805650;hb=655d836ea81170e883cf229573bc5edd0169cee7;hpb=05fb821e72072bde52f383bdc5a988da67f66d0c diff --git a/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java b/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java index f4936b7..9774915 100644 --- a/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages; import static net.pterodactylus.sone.test.GuiceKt.supply; import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo; +import static net.pterodactylus.util.web.Method.GET; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -70,6 +71,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.rules.ExpectedException; import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -125,6 +127,7 @@ public abstract class WebPageTest { @Before public final void setupFreenetRequest() throws SizeLimitExceededException { + setMethod(GET); when(freenetRequest.getToadletContext()).thenReturn(toadletContext); when(freenetRequest.getHttpRequest()).thenReturn(httpRequest); when(httpRequest.getMultipleParam(anyString())).thenAnswer(new Answer() { @@ -290,7 +293,7 @@ public abstract class WebPageTest { 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()); + when(webInterface.getNotifications(Mockito.any())).thenReturn(new ArrayList()); } @Before @@ -308,14 +311,18 @@ public abstract class WebPageTest { when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null); } - protected void request(String uri, Method method) { + protected void setMethod(Method method) { + when(freenetRequest.getMethod()).thenReturn(method); + when(httpRequest.getMethod()).thenReturn(method.name()); + } + + protected void request(String uri) { try { when(httpRequest.getPath()).thenReturn(uri); when(freenetRequest.getUri()).thenReturn(new URI(uri)); } catch (URISyntaxException e) { throw new RuntimeException(e); } - when(freenetRequest.getMethod()).thenReturn(method); } protected void addHttpRequestHeader(@Nonnull String name, String value) { @@ -400,4 +407,13 @@ public abstract class WebPageTest { } } + protected void verifyNoRedirect(Runnable verification) throws RedirectException { + getPage().handleRequest(freenetRequest, templateContext); + verification.run(); + } + + protected void addTranslation(@Nonnull String key, @Nonnull String value) { + when(l10n.getString(key)).thenReturn(value); + } + }