1 package net.pterodactylus.sone.template;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.mockito.Mockito.mock;
5 import static org.mockito.Mockito.never;
6 import static org.mockito.Mockito.verify;
7 import static org.mockito.Mockito.when;
9 import net.pterodactylus.util.template.TemplateContext;
11 import freenet.support.api.HTTPRequest;
13 import org.hamcrest.Matchers;
14 import org.junit.Before;
15 import org.junit.Test;
18 * Unit test for {@link HttpRequestAccessor}.
20 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
22 public class HttpRequestAccessorTest {
24 private static final String REQUEST_PATH = "/the/real/path";
25 private static final String USER_AGENT = "Test/1.0";
26 private static final String HEADER_PATH = "/some/path";
27 private final HttpRequestAccessor accessor = new HttpRequestAccessor();
28 private final TemplateContext context = mock(TemplateContext.class);
29 private final HTTPRequest httpRequest = mock(HTTPRequest.class);
32 public void setupHttpRequest() {
33 when(httpRequest.getPath()).thenReturn(REQUEST_PATH);
34 when(httpRequest.getHeader("User-Agent")).thenReturn(USER_AGENT);
35 when(httpRequest.getHeader("Path")).thenReturn(HEADER_PATH);
39 public void preferCallingMethodsInsteadOfReturningHeaders() {
40 assertThat(accessor.get(context, httpRequest, "path"),
41 Matchers.<Object>is(REQUEST_PATH));
42 verify(httpRequest, never()).getHeader("Path");
46 public void headerIsReturnedCorrectly() {
47 assertThat(accessor.get(context, httpRequest, "User-Agent"),
48 Matchers.<Object>is(USER_AGENT));