From 9a697d5a7801c9e3273010dff321f3290238be63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 28 Jun 2016 21:26:59 +0200 Subject: [PATCH] Move exception matcher to a utils class --- .../sone/web/UploadImagePageTest.java | 23 +------------- .../net/pterodactylus/sone/web/WebTestUtils.java | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 src/test/java/net/pterodactylus/sone/web/WebTestUtils.java diff --git a/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java b/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java index 4b31b90..e74efbd 100644 --- a/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web; +import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.eq; @@ -13,7 +14,6 @@ import net.pterodactylus.sone.core.UpdateChecker; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.web.Method; @@ -21,9 +21,6 @@ import net.pterodactylus.util.web.Method; import freenet.clients.http.ToadletContext; import freenet.support.api.HTTPRequest; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -73,22 +70,4 @@ public class UploadImagePageTest { uploadImagePage.processTemplate(request, templateContext); } - private Matcher redirectsTo(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); - } - }; - } - } 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); + } + }; + } + +} -- 2.7.4