From 6d8f4480444ce0373ac29699b5ead1e4b0d82828 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 24 Nov 2016 21:14:20 +0100 Subject: [PATCH] Add unit test for delete sone page --- .../pterodactylus/sone/web/DeleteSonePageTest.kt | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/DeleteSonePageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/DeleteSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/DeleteSonePageTest.kt new file mode 100644 index 0000000..535aba3 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/DeleteSonePageTest.kt @@ -0,0 +1,43 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.sone.web.WebTestUtils.redirectsTo +import net.pterodactylus.util.web.Method.GET +import net.pterodactylus.util.web.Method.POST +import org.junit.Test +import org.mockito.Mockito.verify +import kotlin.test.fail + +/** + * Unit test for [DeleteSonePage]. + */ +class DeleteSonePageTest : WebPageTest() { + + private val page = DeleteSonePage(template, webInterface) + + @Test + fun `get request does not redirect`() { + request("", GET) + page.handleRequest(freenetRequest, templateContext) + } + + @Test + fun `post request without delete confirmation redirects to index`() { + request("", POST) + expectedException.expect(redirectsTo("index.html")) + page.handleRequest(freenetRequest, templateContext) + } + + @Test + fun `post request with delete confirmation deletes sone and redirects to index`() { + request("", POST) + addHttpRequestParameter("deleteSone", "true") + expectedException.expect(redirectsTo("index.html")) + try { + page.handleRequest(freenetRequest, templateContext) + fail() + } finally { + verify(core).deleteSone(currentSone) + } + } + +} -- 2.7.4