1 package net.pterodactylus.sone.web;
3 import static org.mockito.ArgumentMatchers.anyBoolean;
4 import static org.mockito.ArgumentMatchers.eq;
5 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.when;
10 import java.net.URISyntaxException;
11 import java.util.ArrayList;
13 import net.pterodactylus.sone.core.Core;
14 import net.pterodactylus.sone.core.UpdateChecker;
15 import net.pterodactylus.sone.data.Sone;
16 import net.pterodactylus.sone.web.page.FreenetRequest;
17 import net.pterodactylus.util.notify.Notification;
18 import net.pterodactylus.util.template.Template;
19 import net.pterodactylus.util.template.TemplateContext;
20 import net.pterodactylus.util.web.Method;
22 import freenet.clients.http.ToadletContext;
23 import freenet.support.api.HTTPRequest;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.rules.ExpectedException;
30 * Base class for web page tests.
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public abstract class WebPageTest {
37 public final ExpectedException expectedException = ExpectedException.none();
39 protected final Template template = new Template();
40 protected final WebInterface webInterface = mock(WebInterface.class, RETURNS_DEEP_STUBS);
41 protected final Core core = webInterface.getCore();
43 protected final Sone currentSone = mock(Sone.class);
45 protected final TemplateContext templateContext = new TemplateContext();
46 protected final HTTPRequest httpRequest = mock(HTTPRequest.class);
47 protected final FreenetRequest freenetRequest = mock(FreenetRequest.class);
48 protected final ToadletContext toadletContext = mock(ToadletContext.class);
52 public final void setupFreenetRequest() {
53 when(freenetRequest.getToadletContext()).thenReturn(toadletContext);
54 when(freenetRequest.getHttpRequest()).thenReturn(httpRequest);
58 public final void setupWebInterface() {
59 UpdateChecker updateChecker = mock(UpdateChecker.class);
60 when(webInterface.getCore().getUpdateChecker()).thenReturn(updateChecker);
61 when(webInterface.getCurrentSone(toadletContext)).thenReturn(currentSone);
62 when(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone);
63 when(webInterface.getNotifications(currentSone)).thenReturn(new ArrayList<Notification>());
66 protected void request(String uri, Method method) {
68 when(freenetRequest.getUri()).thenReturn(new URI(uri));
69 } catch (URISyntaxException e) {
70 throw new RuntimeException(e);
72 when(freenetRequest.getMethod()).thenReturn(method);