X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebPageTest.java;h=f7ea06d88d2c79d0704eb54e0d0102f216d99712;hp=71cc9f26d316510c6987a19a2ca1d4b472ae4aea;hb=3734def16a9888d2b904d39ac3a7118f8bc052f9;hpb=331ddfab1cbad04e73d8b92171f3320400ee4664 diff --git a/src/test/java/net/pterodactylus/sone/web/WebPageTest.java b/src/test/java/net/pterodactylus/sone/web/WebPageTest.java index 71cc9f2..f7ea06d 100644 --- a/src/test/java/net/pterodactylus/sone/web/WebPageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/WebPageTest.java @@ -1,5 +1,7 @@ package net.pterodactylus.sone.web; +import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -36,6 +38,7 @@ import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions; import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.web.page.FreenetRequest; +import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -185,6 +188,10 @@ public abstract class WebPageTest { when(currentSone.getOptions()).thenReturn(new DefaultSoneOptions()); } + protected SoneTemplatePage getPage() { + return null; + } + protected void unsetCurrentSone() { when(webInterface.getCurrentSone(toadletContext)).thenReturn(null); when(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(null); @@ -253,4 +260,19 @@ public abstract class WebPageTest { when(webInterface.getNotification(eq(notificationId))).thenReturn(Optional.of(notification)); } + protected void verifyRedirect(String target) throws RedirectException { + expectedException.expect(redirectsTo(target)); + getPage().handleRequest(freenetRequest, templateContext); + } + + protected void verifyRedirect(String target, Runnable verification) throws RedirectException { + expectedException.expect(redirectsTo(target)); + try { + getPage().handleRequest(freenetRequest, templateContext); + fail(); + } finally { + verification.run(); + } + } + }