From 964eb475f03388db63c40635d8843f870a16cf85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 21 Jan 2017 16:52:58 +0100 Subject: [PATCH] Add unit test for unlock sone page --- .../pterodactylus/sone/web/UnlockSonePageTest.kt | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/UnlockSonePageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/UnlockSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/UnlockSonePageTest.kt new file mode 100644 index 0000000..4785156 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/UnlockSonePageTest.kt @@ -0,0 +1,58 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.junit.Test +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.never +import org.mockito.Mockito.verify + +/** + * Unit test for [UnlockSonePage]. + */ +class UnlockSonePageTest : WebPageTest() { + + private val page = UnlockSonePage(template, webInterface) + + override fun getPage() = page + + @Test + fun `get request without sone redirects to return page`() { + addHttpRequestParameter("returnPage", "return.html") + verifyRedirect("return.html") { + verify(core, never()).unlockSone(any()) + } + } + + @Test + fun `get request without invalid local sone does not unlock any sone and redirects to return page`() { + addHttpRequestParameter("returnPage", "return.html") + addHttpRequestParameter("sone", "invalid-sone") + verifyRedirect("return.html") { + verify(core, never()).unlockSone(any()) + } + } + + @Test + fun `get request without remote sone does not unlock any sone and redirects to return page`() { + addHttpRequestParameter("returnPage", "return.html") + addHttpRequestParameter("sone", "remote-sone") + addSone("remote-sone", mock()) + verifyRedirect("return.html") { + verify(core, never()).unlockSone(any()) + } + } + + @Test + fun `get request with local sone unlocks sone and redirects to return page`() { + addHttpRequestParameter("returnPage", "return.html") + addHttpRequestParameter("sone", "local-sone") + val sone = mock().apply { whenever(isLocal).thenReturn(true) } + addLocalSone("local-sone", sone) + verifyRedirect("return.html") { + verify(core).unlockSone(sone) + } + } + +} -- 2.7.4