Remove method to bookmark a post by ID.
[Sone.git] / src / test / java / net / pterodactylus / sone / template / HttpRequestAccessorTest.java
1 package net.pterodactylus.sone.template;
2
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;
8
9 import net.pterodactylus.util.template.TemplateContext;
10
11 import freenet.support.api.HTTPRequest;
12
13 import org.hamcrest.Matchers;
14 import org.junit.Before;
15 import org.junit.Test;
16
17 /**
18  * Unit test for {@link HttpRequestAccessor}.
19  *
20  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
21  */
22 public class HttpRequestAccessorTest {
23
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);
30
31         @Before
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);
36         }
37
38         @Test
39         public void preferCallingMethodsInsteadOfReturningHeaders() {
40                 assertThat(accessor.get(context, httpRequest, "path"),
41                                 Matchers.<Object>is(REQUEST_PATH));
42                 verify(httpRequest, never()).getHeader("Path");
43         }
44
45         @Test
46         public void headerIsReturnedCorrectly() {
47                 assertThat(accessor.get(context, httpRequest, "User-Agent"),
48                                 Matchers.<Object>is(USER_AGENT));
49         }
50
51 }