X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FUploadImagePageTest.java;h=3b8258e0c8a1588e2011780fd21dbcc8723dde4c;hb=10d9eb5fcea8440b9ea06a3732678b286090934f;hp=4b31b900a961751b03a9eb993b48dc4432bda356;hpb=d14d3498b42feaf7b5ae6390910c106ce4823234;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java b/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java
index 4b31b90..3b8258e 100644
--- a/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java
+++ b/src/test/java/net/pterodactylus/sone/web/UploadImagePageTest.java
@@ -1,64 +1,29 @@
package net.pterodactylus.sone.web;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
+import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.net.URI;
-
-import net.pterodactylus.sone.core.Core;
-import net.pterodactylus.sone.core.UpdateChecker;
import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.web.Method;
-import freenet.clients.http.ToadletContext;
-import freenet.support.api.HTTPRequest;
-
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
/**
* Unit test for {@link UploadImagePageTest}.
*
* @author David âBombeâ Roden
*/
-public class UploadImagePageTest {
-
- @Rule
- public final ExpectedException expectedException = ExpectedException.none();
+public class UploadImagePageTest extends WebPageTest {
- private final Template template = new Template();
- private final WebInterface webInterface = mock(WebInterface.class);
private final UploadImagePage uploadImagePage = new UploadImagePage(template, webInterface);
- private final TemplateContext templateContext = new TemplateContext();
- private final HTTPRequest httpRequest = mock(HTTPRequest.class);
- private final ToadletContext toadletContext = mock(ToadletContext.class);
- private final Core core = mock(Core.class);
- private final Sone currentSone = mock(Sone.class);
private final Album parentAlbum = mock(Album.class);
@Before
- public void setupWebInterface() {
- UpdateChecker updateChecker = mock(UpdateChecker.class);
- when(core.getUpdateChecker()).thenReturn(updateChecker);
- when(webInterface.getCore()).thenReturn(core);
- when(webInterface.getCurrentSone(any(ToadletContext.class))).thenReturn(currentSone);
- }
-
- @Before
public void setupParentAlbum() {
when(core.getAlbum("parent-id")).thenReturn(parentAlbum);
when(parentAlbum.getSone()).thenReturn(currentSone);
@@ -66,29 +31,11 @@ public class UploadImagePageTest {
@Test
public void uploadingAnImageWithoutTitleRedirectsToEmptyImageTitlePage() throws Exception {
- FreenetRequest request = new FreenetRequest(new URI(""), Method.POST, httpRequest, toadletContext);
+ request("", Method.POST);
when(httpRequest.getPartAsStringFailsafe(eq("parent"), anyInt())).thenReturn("parent-id");
when(httpRequest.getPartAsStringFailsafe(eq("title"), anyInt())).thenReturn(" ");
expectedException.expect(redirectsTo("emptyImageTitle.html"));
- uploadImagePage.processTemplate(request, templateContext);
- }
-
- private Matcher redirectsTo(final String page) {
- return new TypeSafeDiagnosingMatcher() {
- @Override
- protected boolean matchesSafely(RedirectException exception, Description mismatchDescription) {
- if (!exception.getTarget().equals(page)) {
- mismatchDescription.appendText("target is ").appendValue(exception.getTarget());
- return false;
- }
- return true;
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("target is ").appendValue(page);
- }
- };
+ uploadImagePage.processTemplate(freenetRequest, templateContext);
}
}