1 package net.pterodactylus.sone.fcp
3 import net.pterodactylus.sone.core.Core
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.sone.utils.asOptional
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Before
10 import org.mockito.Mockito.verify
13 * Unit test for [UnlockSoneCommand].
15 class UnlockSoneCommandTest : SoneCommandTest() {
17 override fun createCommand(core: Core) = UnlockSoneCommand(core)
21 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional())
22 whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional())
23 whenever(localSone.id).thenReturn("LocalSoneId")
27 fun `command requires write access`() {
28 assertThat(command.requiresWriteAccess(), equalTo(true))
32 fun `request without any parameters results in FCP exception`() {
33 requestWithoutAnyParameterResultsInFcpException()
37 fun `request with invalid sone parameter results in FCP exception`() {
38 requestWithInvalidSoneParameterResultsInFcpException()
42 fun `request with valid remote sone parameter results in FCP exception`() {
43 requestWithValidRemoteSoneParameterResultsInFcpException()
47 fun `request with local sone parameter unlocks the sone`() {
48 parameters += "Sone" to "LocalSoneId"
49 val replyParameters = command.execute(parameters).replyParameters
50 assertThat(replyParameters["Message"], equalTo("SoneUnlocked"))
51 assertThat(replyParameters["Sone"], equalTo("LocalSoneId"))
52 verify(core).unlockSone(localSone)