Add unit test for delete sone page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 24 Nov 2016 20:14:20 +0000 (21:14 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 24 Nov 2016 20:14:20 +0000 (21:14 +0100)
src/test/kotlin/net/pterodactylus/sone/web/DeleteSonePageTest.kt [new file with mode: 0644]

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 (file)
index 0000000..535aba3
--- /dev/null
@@ -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)
+               }
+       }
+
+}