From 8883cd2aa6d2294e10259f7a5338e6c16b26c8b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 27 Nov 2016 15:12:50 +0100 Subject: [PATCH] Add unit test for lock sone page --- .../net/pterodactylus/sone/web/LockSonePageTest.kt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/LockSonePageTest.kt 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) + } + } + +} -- 2.7.4