Simplify verifying that no redirect is called
[Sone.git] / src / test / java / net / pterodactylus / sone / web / pages / WebPageTest.java
index f4936b7..c785e36 100644 (file)
@@ -70,6 +70,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -290,7 +291,7 @@ public abstract class WebPageTest {
                when(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone);
                when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone);
                when(webInterface.getNotification(anyString())).thenReturn(Optional.<Notification>absent());
-               when(webInterface.getNotifications(currentSone)).thenReturn(new ArrayList<Notification>());
+               when(webInterface.getNotifications(Mockito.<Sone>any())).thenReturn(new ArrayList<Notification>());
        }
 
        @Before
@@ -308,6 +309,11 @@ public abstract class WebPageTest {
                when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null);
        }
 
+       protected void setMethod(Method method) {
+               when(freenetRequest.getMethod()).thenReturn(method);
+               when(httpRequest.getMethod()).thenReturn(method.name());
+       }
+
        protected void request(String uri, Method method) {
                try {
                        when(httpRequest.getPath()).thenReturn(uri);
@@ -316,6 +322,7 @@ public abstract class WebPageTest {
                        throw new RuntimeException(e);
                }
                when(freenetRequest.getMethod()).thenReturn(method);
+               when(httpRequest.getMethod()).thenReturn(method.name());
        }
 
        protected void addHttpRequestHeader(@Nonnull String name, String value) {
@@ -400,4 +407,13 @@ public abstract class WebPageTest {
                }
        }
 
+       protected void verifyNoRedirect(Runnable verification) throws RedirectException {
+               getPage().handleRequest(freenetRequest, templateContext);
+               verification.run();
+       }
+
+       protected void addTranslation(@Nonnull String key, @Nonnull String value) {
+               when(l10n.getString(key)).thenReturn(value);
+       }
+
 }