From: David ‘Bombe’ Roden Date: Sat, 21 Jan 2017 15:52:58 +0000 (+0100) Subject: Add unit test for unlock sone page X-Git-Tag: 0.9.7^2~324 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=964eb475f03388db63c40635d8843f870a16cf85;p=Sone.git Add unit test for unlock sone page --- 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) + } + } + +}