Mock the HTTP request, too.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 9 Feb 2014 10:56:13 +0000 (11:56 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:26:08 +0000 (22:26 +0100)
src/test/java/net/pterodactylus/sone/data/Mocks.java
src/test/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPageTest.java

index e4449c4..72a4e75 100644 (file)
@@ -166,8 +166,10 @@ public class Mocks {
                return new PostReplyMocker(replyId, sone);
        }
 
-       public FreenetRequest mockRequest(String path) throws URISyntaxException {
-               HTTPRequest httpRequest = new HTTPRequestImpl(new URI(path), "GET");
+       public FreenetRequest mockRequest(String path) {
+               HTTPRequest httpRequest = mock(HTTPRequest.class);
+               when(httpRequest.getMethod()).thenReturn("GET");
+               when(httpRequest.getPath()).thenReturn(path);
                FreenetRequest request = mock(FreenetRequest.class);
                when(request.getHttpRequest()).thenReturn(httpRequest);
                return request;
index 0239464..ed07a5b 100644 (file)
@@ -13,6 +13,7 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.net.URISyntaxException;
 
@@ -42,20 +43,22 @@ public class BookmarkAjaxPageTest {
 
        @Test
        public void testBookmarkingExistingPost() throws URISyntaxException {
-               JsonReturnObject jsonReturnObject = performRequest("/ajax/bookmark.ajax?post=abc", bookmarkAjaxPage);
+               JsonReturnObject jsonReturnObject = performRequest(bookmarkAjaxPage, "abc");
                verifySuccessfulJsonResponse(jsonReturnObject);
                verify(core, times(1)).bookmarkPost(eq("abc"));
        }
 
        @Test
        public void testBookmarkingMissingPost() throws URISyntaxException {
-               JsonReturnObject jsonReturnObject = performRequest("/ajax/bookmark.ajax", bookmarkAjaxPage);
+               JsonReturnObject jsonReturnObject = performRequest(bookmarkAjaxPage, null);
                verifyJsonError(jsonReturnObject, "invalid-post-id");
                verify(core, never()).bookmarkPost(anyString());
        }
 
-       private JsonReturnObject performRequest(String path, BookmarkAjaxPage bookmarkAjaxPage) throws URISyntaxException {
-               FreenetRequest request = mocks.mockRequest(path);
+       private JsonReturnObject performRequest(BookmarkAjaxPage bookmarkAjaxPage, String postId) throws URISyntaxException {
+               FreenetRequest request = mocks.mockRequest("");
+               when(request.getHttpRequest().getParam("post")).thenReturn(postId);
+               when(request.getHttpRequest().getParam("post", null)).thenReturn(postId);
                return bookmarkAjaxPage.createJsonObject(request);
        }