X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FDismissNotificationPageTest.kt;h=3c19f5c9260828025e99f937b6ee245e54b78078;hp=a794f4c21a150794a908addbb379902d25ebc022;hb=9acbc5bdec4ccb752e0856a501568b0bb6161579;hpb=8aebcf573e7b5ef8b7b09f1c90c4f12a82920b64 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/DismissNotificationPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/DismissNotificationPageTest.kt index a794f4c..3c19f5c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/DismissNotificationPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/DismissNotificationPageTest.kt @@ -2,57 +2,66 @@ package net.pterodactylus.sone.web import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever -import net.pterodactylus.sone.web.WebTestUtils.redirectsTo import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.web.Method.GET +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo import org.junit.Test import org.mockito.Mockito.never import org.mockito.Mockito.verify -import kotlin.test.fail /** * Unit test for [DismissNotificationPage]. */ -class DismissNotificationPageTest : WebPageTest() { +class DismissNotificationPageTest: WebPageTest() { private val page = DismissNotificationPage(template, webInterface) private val notification = mock() + override fun getPage() = page + + @Test + fun `page returns correct path`() { + assertThat(page.path, equalTo("dismissNotification.html")) + } + + @Test + fun `page does not require login`() { + assertThat(page.requiresLogin(), equalTo(false)) + } + + @Test + fun `page returns correct title`() { + whenever(l10n.getString("Page.DismissNotification.Title")).thenReturn("dismiss notification page") + assertThat(page.getPageTitle(freenetRequest), equalTo("dismiss notification page")) + } + @Test fun `get request with invalid notification ID redirects to return page`() { request("", GET) addHttpRequestParameter("returnPage", "return.html") - expectedException.expect(redirectsTo("return.html")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("return.html") } @Test - fun `get request with dismissible notification dismisses the notification and redirects to return page`() { + fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() { request("", GET) addNotification("notification-id", notification) addHttpRequestParameter("notification", "notification-id") addHttpRequestParameter("returnPage", "return.html") - expectedException.expect(redirectsTo("return.html")) - try { - page.handleRequest(freenetRequest, templateContext) - fail() - } finally { + verifyRedirect("return.html") { verify(notification, never()).dismiss() } } @Test - fun `get request with non dismissible notification redirects to return page`() { + fun `get request with dismissible notification dismisses the notification and redirects to return page`() { request("", GET) whenever(notification.isDismissable).thenReturn(true) addNotification("notification-id", notification) addHttpRequestParameter("notification", "notification-id") addHttpRequestParameter("returnPage", "return.html") - expectedException.expect(redirectsTo("return.html")) - try { - page.handleRequest(freenetRequest, templateContext) - fail() - } finally { + verifyRedirect("return.html") { verify(notification).dismiss() } }