import static net.pterodactylus.sone.test.GuiceKt.supply;
import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
+import static net.pterodactylus.util.web.Method.GET;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
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;
@Before
public final void setupFreenetRequest() throws SizeLimitExceededException {
+ setMethod(GET);
when(freenetRequest.getToadletContext()).thenReturn(toadletContext);
when(freenetRequest.getHttpRequest()).thenReturn(httpRequest);
when(httpRequest.getMultipleParam(anyString())).thenAnswer(new Answer<String[]>() {
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
when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null);
}
- protected void request(String uri, Method method) {
+ protected void setMethod(Method method) {
+ when(freenetRequest.getMethod()).thenReturn(method);
+ when(httpRequest.getMethod()).thenReturn(method.name());
+ }
+
+ protected void request(String uri) {
try {
when(httpRequest.getPath()).thenReturn(uri);
when(freenetRequest.getUri()).thenReturn(new URI(uri));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
- when(freenetRequest.getMethod()).thenReturn(method);
}
protected void addHttpRequestHeader(@Nonnull String name, String value) {
}
}
+ 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);
+ }
+
}