Rewrite test to use JUnit 4
[Sone.git] / src / test / java / net / pterodactylus / sone / web / DeleteReplyPageTest.java
1 package net.pterodactylus.sone.web;
2
3 import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
4 import static org.mockito.Matchers.anyInt;
5 import static org.mockito.Matchers.eq;
6 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
7 import static org.mockito.Mockito.mock;
8 import static org.mockito.Mockito.when;
9
10 import java.util.Collections;
11
12 import net.pterodactylus.sone.data.PostReply;
13 import net.pterodactylus.sone.data.Sone;
14 import net.pterodactylus.sone.web.page.FreenetRequest;
15 import net.pterodactylus.util.notify.Notification;
16 import net.pterodactylus.util.template.Template;
17 import net.pterodactylus.util.template.TemplateContext;
18 import net.pterodactylus.util.web.Method;
19
20 import freenet.support.api.HTTPRequest;
21
22 import com.google.common.base.Optional;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.mockito.Matchers;
28
29 /**
30  * Unit test for {@link DeleteReplyPage}.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33  */
34 public class DeleteReplyPageTest {
35
36         @Rule
37         public final ExpectedException expectedException = ExpectedException.none();
38
39         private final Template template = new Template();
40         private final WebInterface webInterface = mock(WebInterface.class, RETURNS_DEEP_STUBS);
41         private final DeleteReplyPage page = new DeleteReplyPage(template, webInterface);
42         private final TemplateContext templateContext = new TemplateContext();
43         private final FreenetRequest freenetRequest = mock(FreenetRequest.class);
44         private final HTTPRequest httpRequest = mock(HTTPRequest.class);
45
46         @Before
47         public void setupWebInterface() {
48                 when(webInterface.getNotifications(Matchers.any(Sone.class))).thenReturn(Collections.<Notification>emptyList());
49         }
50
51         @Before
52         public void setupHttpRequest() {
53                 when(freenetRequest.getHttpRequest()).thenReturn(httpRequest);
54         }
55
56         @Test
57         public void tryingToDeleteAReplyWithAnInvalidIdResultsInNoPermissionPage() throws Exception {
58                 when(freenetRequest.getMethod()).thenReturn(Method.POST);
59                 when(httpRequest.getPartAsStringFailsafe(eq("reply"), anyInt())).thenReturn("id");
60                 when(webInterface.getCore().getPostReply("id")).thenReturn(Optional.<PostReply>absent());
61                 expectedException.expect(redirectsTo("noPermission.html"));
62                 page.processTemplate(freenetRequest, templateContext);
63         }
64
65 }