Add test for CreateReplyPage
[Sone.git] / src / test / java / net / pterodactylus / sone / web / WebPageTest.java
index 1a6fb59..bb6282c 100644 (file)
@@ -2,6 +2,7 @@ package net.pterodactylus.sone.web;
 
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
@@ -57,12 +58,21 @@ public abstract class WebPageTest {
        public final void setupFreenetRequest() {
                when(freenetRequest.getToadletContext()).thenReturn(toadletContext);
                when(freenetRequest.getHttpRequest()).thenReturn(httpRequest);
+               when(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).thenAnswer(new Answer<String>() {
+                       @Override
+                       public String answer(InvocationOnMock invocation) throws Throwable {
+                               return "";
+                       }
+               });
        }
 
        @Before
        public final void setupCore() {
                UpdateChecker updateChecker = mock(UpdateChecker.class);
-               when(webInterface.getCore().getUpdateChecker()).thenReturn(updateChecker);
+               when(core.getUpdateChecker()).thenReturn(updateChecker);
+               when(core.getLocalSone(anyString())).thenReturn(null);
+               when(core.getSone(anyString())).thenReturn(Optional.<Sone>absent());
+               when(core.getPost(anyString())).thenReturn(Optional.<Post>absent());
        }
 
        @Before
@@ -95,4 +105,12 @@ public abstract class WebPageTest {
                when(core.getPost(postId)).thenReturn(Optional.fromNullable(post));
        }
 
+       protected void addSone(String soneId, Sone sone) {
+               when(core.getSone(eq(soneId))).thenReturn(Optional.fromNullable(sone));
+       }
+
+       protected void addLocalSone(String soneId, Sone sone) {
+               when(core.getLocalSone(eq(soneId))).thenReturn(sone);
+       }
+
 }