d4e7596fb8499da6458b62a18695777ca0c83849
[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  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
15  */
16 public class WebTestUtils {
17
18         @Nonnull
19         public static Matcher<RedirectException> redirectsTo(@Nonnull final String page) {
20                 return new TypeSafeDiagnosingMatcher<RedirectException>() {
21                         @Override
22                         protected boolean matchesSafely(RedirectException exception, Description mismatchDescription) {
23                                 if (!exception.getTarget().equals(page)) {
24                                         mismatchDescription.appendText("target is ").appendValue(exception.getTarget());
25                                         return false;
26                                 }
27                                 return true;
28                         }
29
30                         @Override
31                         public void describeTo(Description description) {
32                                 description.appendText("target is ").appendValue(page);
33                         }
34                 };
35         }
36
37 }