Replace delete post page with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / DismissNotificationPageTest.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.test.mock
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.util.notify.Notification
6 import net.pterodactylus.util.web.Method.GET
7 import org.junit.Test
8 import org.mockito.Mockito.never
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [DismissNotificationPage].
13  */
14 class DismissNotificationPageTest : WebPageTest() {
15
16         private val page = DismissNotificationPage(template, webInterface)
17         private val notification = mock<Notification>()
18
19         override fun getPage() = page
20
21         @Test
22         fun `get request with invalid notification ID redirects to return page`() {
23                 request("", GET)
24                 addHttpRequestParameter("returnPage", "return.html")
25                 verifyRedirect("return.html")
26         }
27
28         @Test
29         fun `get request with dismissible notification dismisses the notification and redirects to return page`() {
30                 request("", GET)
31                 addNotification("notification-id", notification)
32                 addHttpRequestParameter("notification", "notification-id")
33                 addHttpRequestParameter("returnPage", "return.html")
34                 verifyRedirect("return.html") {
35                         verify(notification, never()).dismiss()
36                 }
37         }
38
39         @Test
40         fun `get request with non dismissible notification redirects to return page`() {
41                 request("", GET)
42                 whenever(notification.isDismissable).thenReturn(true)
43                 addNotification("notification-id", notification)
44                 addHttpRequestParameter("notification", "notification-id")
45                 addHttpRequestParameter("returnPage", "return.html")
46                 verifyRedirect("return.html") {
47                         verify(notification).dismiss()
48                 }
49         }
50
51 }