From: David ‘Bombe’ Roden Date: Thu, 24 Nov 2016 20:14:20 +0000 (+0100) Subject: Add unit test for delete sone page X-Git-Tag: 0.9.7^2~397 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6d8f4480444ce0373ac29699b5ead1e4b0d82828;p=Sone.git Add unit test for delete sone page --- 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) + } + } + +}