🔀 Merge branch 'release/v82'
[Sone.git] / src / test / java / net / pterodactylus / sone / web / WebTestUtils.java
1 package net.pterodactylus.sone.web;
2
3 import javax.annotation.Nonnull;
4
5 import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException;
6
7 import org.hamcrest.Description;
8 import org.hamcrest.Matcher;
9 import org.hamcrest.TypeSafeDiagnosingMatcher;
10
11 /**
12  * Utilities for testing the <code>web</code> package.
13  */
14 public class WebTestUtils {
15
16         @Nonnull
17         public static Matcher<RedirectException> redirectsTo(@Nonnull final String page) {
18                 return new TypeSafeDiagnosingMatcher<RedirectException>() {
19                         @Override
20                         protected boolean matchesSafely(RedirectException exception, Description mismatchDescription) {
21                                 if (!exception.getTarget().equals(page)) {
22                                         mismatchDescription.appendText("target is ").appendValue(exception.getTarget());
23                                         return false;
24                                 }
25                                 return true;
26                         }
27
28                         @Override
29                         public void describeTo(Description description) {
30                                 description.appendText("target is ").appendValue(page);
31                         }
32                 };
33         }
34
35 }