1 package net.pterodactylus.sone.template;
3 import static org.mockito.Mockito.mock;
4 import static org.mockito.Mockito.verify;
5 import static org.mockito.Mockito.when;
7 import java.util.HashMap;
10 import net.pterodactylus.sone.web.page.FreenetRequest;
11 import net.pterodactylus.util.template.TemplateContext;
13 import freenet.support.api.HTTPRequest;
15 import org.junit.Before;
16 import org.junit.Test;
19 * Unit test for {@link GetPagePlugin}.
21 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
23 public class GetPagePluginTest {
25 private final GetPagePlugin plugin = new GetPagePlugin();
26 private final TemplateContext context = mock(TemplateContext.class);
27 private final FreenetRequest request = mock(FreenetRequest.class);
28 private final Map<String, String> parameters =
29 new HashMap<String, String>();
30 private HTTPRequest httpRequest = mock(HTTPRequest.class);
33 public void setupTemplateContext() {
34 when(context.get("request")).thenReturn(request);
35 when(request.getHttpRequest()).thenReturn(httpRequest);
36 when(httpRequest.getParam("page")).thenReturn("1");
40 public void fullySpecifiedPluginCallSetsCorrectValue() {
41 parameters.put("request", "request");
42 parameters.put("parameter", "page");
43 parameters.put("key", "page-key");
44 plugin.execute(context, parameters);
45 verify(context).set("page-key", 1);
49 public void missingRequestParameterStillSetsCorrectValue() {
50 parameters.put("parameter", "page");
51 parameters.put("key", "page-key");
52 plugin.execute(context, parameters);
53 verify(context).set("page-key", 1);
57 public void missingParameterParameterStillSetsCorrectValue() {
58 parameters.put("request", "request");
59 parameters.put("key", "page-key");
60 plugin.execute(context, parameters);
61 verify(context).set("page-key", 1);
65 public void missingKeyParameterStillSetsCorrectValue() {
66 parameters.put("request", "request");
67 parameters.put("parameter", "page");
68 plugin.execute(context, parameters);
69 verify(context).set("page", 1);
73 public void unparseablePageSetsPageZero() {
74 parameters.put("parameter", "wrong-parameter");
75 plugin.execute(context, parameters);
76 verify(context).set("page", 0);