Add test for bookmark page
[Sone.git] / src / test / java / net / pterodactylus / sone / web / UploadImagePageTest.java
1 package net.pterodactylus.sone.web;
2
3 import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
4 import static org.mockito.ArgumentMatchers.anyInt;
5 import static org.mockito.ArgumentMatchers.eq;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.when;
8
9 import net.pterodactylus.sone.data.Album;
10 import net.pterodactylus.util.web.Method;
11
12 import org.junit.Before;
13 import org.junit.Test;
14
15 /**
16  * Unit test for {@link UploadImagePageTest}.
17  *
18  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19  */
20 public class UploadImagePageTest extends WebPageTest {
21
22         private final UploadImagePage uploadImagePage = new UploadImagePage(template, webInterface);
23
24         private final Album parentAlbum = mock(Album.class);
25
26         @Before
27         public void setupParentAlbum() {
28                 when(core.getAlbum("parent-id")).thenReturn(parentAlbum);
29                 when(parentAlbum.getSone()).thenReturn(currentSone);
30         }
31
32         @Test
33         public void uploadingAnImageWithoutTitleRedirectsToEmptyImageTitlePage() throws Exception {
34                 request("", Method.POST);
35                 when(httpRequest.getPartAsStringFailsafe(eq("parent"), anyInt())).thenReturn("parent-id");
36                 when(httpRequest.getPartAsStringFailsafe(eq("title"), anyInt())).thenReturn("  ");
37                 expectedException.expect(redirectsTo("emptyImageTitle.html"));
38                 uploadImagePage.processTemplate(freenetRequest, templateContext);
39         }
40
41 }