Add unit test for lock sone page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 27 Nov 2016 14:12:50 +0000 (15:12 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 27 Nov 2016 14:12:50 +0000 (15:12 +0100)
src/test/kotlin/net/pterodactylus/sone/web/LockSonePageTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/LockSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/LockSonePageTest.kt
new file mode 100644 (file)
index 0000000..44cd81c
--- /dev/null
@@ -0,0 +1,42 @@
+package net.pterodactylus.sone.web
+
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.mock
+import org.junit.Test
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.never
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [LockSonePage].
+ */
+class LockSonePageTest : WebPageTest() {
+
+       private val page = LockSonePage(template, webInterface)
+
+       @Test
+       fun `locking an invalid local sone redirects to return page`() {
+               addHttpRequestParameter("returnPage", "return.html")
+               expectedException.expect(WebTestUtils.redirectsTo("return.html"))
+               try {
+                       page.handleRequest(freenetRequest, templateContext)
+               } finally {
+                       verify(core, never()).lockSone(any<Sone>())
+               }
+       }
+
+       @Test
+       fun `locking an valid local sone locks the sone and redirects to return page`() {
+               addHttpRequestParameter("sone", "sone-id")
+               val sone = mock<Sone>()
+               addLocalSone("sone-id", sone)
+               addHttpRequestParameter("returnPage", "return.html")
+               expectedException.expect(WebTestUtils.redirectsTo("return.html"))
+               try {
+                       page.handleRequest(freenetRequest, templateContext)
+               } finally {
+                       verify(core).lockSone(sone)
+               }
+       }
+
+}