X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FUnlockSoneCommandTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FUnlockSoneCommandTest.kt;h=5edc03e52c46d996be16c099cedba28da9148a04;hb=6b374dc7e910f36a2d79499c865b6c5a7931b7ae;hp=0000000000000000000000000000000000000000;hpb=8e757d5c4e370192094ad844d88935c3c714c34b;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.kt new file mode 100644 index 0000000..5edc03e --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.kt @@ -0,0 +1,55 @@ +package net.pterodactylus.sone.fcp + +import net.pterodactylus.sone.core.Core +import net.pterodactylus.sone.test.asOptional +import net.pterodactylus.sone.test.whenever +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [UnlockSoneCommand]. + */ +class UnlockSoneCommandTest : SoneCommandTest() { + + override fun createCommand(core: Core) = UnlockSoneCommand(core) + + @Before + fun setupSones() { + whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional()) + whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional()) + whenever(localSone.id).thenReturn("LocalSoneId") + } + + @Test + fun `command requires write access`() { + assertThat(command.requiresWriteAccess(), equalTo(true)) + } + + @Test + fun `request without any parameters results in FCP exception`() { + requestWithoutAnyParameterResultsInFcpException() + } + + @Test + fun `request with invalid sone parameter results in FCP exception`() { + requestWithInvalidSoneParameterResultsInFcpException() + } + + @Test + fun `request with valid remote sone parameter results in FCP exception`() { + requestWithValidRemoteSoneParameterResultsInFcpException() + } + + @Test + fun `request with local sone parameter unlocks the sone`() { + parameters += "Sone" to "LocalSoneId" + val replyParameters = command.execute(parameters).replyParameters + assertThat(replyParameters["Message"], equalTo("SoneUnlocked")) + assertThat(replyParameters["Sone"], equalTo("LocalSoneId")) + verify(core).unlockSone(localSone) + } + +}