Remove obsolete loading animation
[Sone.git] / src / test / java / net / pterodactylus / sone / web / WebPageTest.java
index bd6ff9d..6f99879 100644 (file)
@@ -1,5 +1,6 @@
 package net.pterodactylus.sone.web;
 
+import static net.pterodactylus.sone.test.GuiceKt.supply;
 import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -60,6 +61,8 @@ import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Multimap;
 import com.google.common.eventbus.EventBus;
 import com.google.common.io.ByteStreams;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.rules.ExpectedException;
@@ -103,6 +106,11 @@ public abstract class WebPageTest {
        protected final List<Sone> localSones = new ArrayList<>();
        private final ListMultimap<String, PostReply> postReplies = ArrayListMultimap.create();
 
+       protected final Injector injector = Guice.createInjector(
+                       supply(WebInterface.class).byInstance(webInterface),
+                       supply(Template.class).byInstance(template)
+       );
+
        protected WebPageTest() {
                try {
                        responseInputStream = new PipedInputStream(responseOutputStream);
@@ -156,6 +164,13 @@ public abstract class WebPageTest {
                                return requestParameters.containsKey(parameter) ? requestParameters.get(parameter).iterator().next() : invocation.<String>getArgument(1);
                        }
                });
+               when(httpRequest.isParameterSet(anyString())).thenAnswer(new Answer<Boolean>() {
+                       @Override
+                       public Boolean answer(InvocationOnMock invocation) throws Throwable {
+                               return requestParameters.containsKey(invocation.<String>getArgument(0)) &&
+                                               requestParameters.get(invocation.<String>getArgument(0)).iterator().next() != null;
+                       }
+               });
                when(httpRequest.isPartSet(anyString())).thenAnswer(new Answer<Boolean>() {
                        @Override
                        public Boolean answer(InvocationOnMock invocation) throws Throwable {
@@ -228,6 +243,7 @@ public abstract class WebPageTest {
                        }
                });
                when(core.getPost(anyString())).thenReturn(Optional.<Post>absent());
+               when(core.getPostReply(anyString())).thenReturn(Optional.<PostReply>absent());
                when(core.getReplies(anyString())).thenAnswer(new Answer<List<PostReply>>() {
                        @Override
                        public List<PostReply> answer(InvocationOnMock invocation) throws Throwable {
@@ -257,8 +273,8 @@ public abstract class WebPageTest {
 
        @Before
        public final void setupWebInterface() {
-               when(webInterface.getCurrentSone(toadletContext)).thenReturn(currentSone);
-               when(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone);
+               when(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone);
+               when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone);
                when(webInterface.getNotification(anyString())).thenReturn(Optional.<Notification>absent());
                when(webInterface.getNotifications(currentSone)).thenReturn(new ArrayList<Notification>());
        }
@@ -273,8 +289,8 @@ public abstract class WebPageTest {
        }
 
        protected void unsetCurrentSone() {
-               when(webInterface.getCurrentSone(toadletContext)).thenReturn(null);
-               when(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(null);
+               when(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(null);
+               when(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null);
        }
 
        protected void request(String uri, Method method) {