X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebTestUtils.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebTestUtils.java;h=d4e7596fb8499da6458b62a18695777ca0c83849;hb=9a697d5a7801c9e3273010dff321f3290238be63;hp=0000000000000000000000000000000000000000;hpb=3deb6ce4991df3aa98934154455c2a96be753c4d;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/web/WebTestUtils.java b/src/test/java/net/pterodactylus/sone/web/WebTestUtils.java new file mode 100644 index 0000000..d4e7596 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/web/WebTestUtils.java @@ -0,0 +1,37 @@ +package net.pterodactylus.sone.web; + +import javax.annotation.Nonnull; + +import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; + +/** + * Utilities for testing the web package. + * + * @author David ‘Bombe’ Roden + */ +public class WebTestUtils { + + @Nonnull + public static Matcher redirectsTo(@Nonnull final String page) { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(RedirectException exception, Description mismatchDescription) { + if (!exception.getTarget().equals(page)) { + mismatchDescription.appendText("target is ").appendValue(exception.getTarget()); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("target is ").appendValue(page); + } + }; + } + +}