From: David ‘Bombe’ Roden Date: Sun, 27 Nov 2016 14:12:50 +0000 (+0100) Subject: Add unit test for lock sone page X-Git-Tag: 0.9.7^2~381 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8883cd2aa6d2294e10259f7a5338e6c16b26c8b2;p=Sone.git Add unit test for lock sone page --- 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 index 0000000..44cd81c --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/LockSonePageTest.kt @@ -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()) + } + } + + @Test + fun `locking an valid local sone locks the sone and redirects to return page`() { + addHttpRequestParameter("sone", "sone-id") + val sone = mock() + addLocalSone("sone-id", sone) + addHttpRequestParameter("returnPage", "return.html") + expectedException.expect(WebTestUtils.redirectsTo("return.html")) + try { + page.handleRequest(freenetRequest, templateContext) + } finally { + verify(core).lockSone(sone) + } + } + +}