X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FSoneCommandTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FSoneCommandTest.kt;h=b2fb4aeea47e61a85bd3ca266232e5299eb4cfd3;hb=00c0f66598af0a462cb367fbf1ad67512878cf5e;hp=0000000000000000000000000000000000000000;hpb=b43aa662e0888130d40ce93fcc38df46563d33c3;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt new file mode 100644 index 0000000..b2fb4ae --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt @@ -0,0 +1,66 @@ +package net.pterodactylus.sone.fcp + +import com.google.common.base.Optional +import com.google.common.base.Optional.absent +import freenet.support.SimpleFieldSet +import net.pterodactylus.sone.core.Core +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.freenet.fcp.Command +import net.pterodactylus.sone.freenet.fcp.FcpException +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.rules.ExpectedException +import org.mockito.ArgumentMatchers +import org.mockito.ArgumentMatchers.anyString + +/** + * TODO + */ +abstract class SoneCommandTest { + + @Rule @JvmField val expectedException = ExpectedException.none()!! + + protected val core = mock() + protected val command: AbstractSoneCommand by lazy { createCommand(core) } + + protected val parameters = SimpleFieldSet(true) + protected val localSone = mock().apply { + whenever(isLocal).thenReturn(true) + } + protected val remoteSone = mock() + + protected abstract fun createCommand(core: Core): AbstractSoneCommand + + @Before + fun setupCore() { + whenever(core.getSone(anyString())).thenReturn(absent()) + } + + protected fun requestWithoutAnyParameterResultsInFcpException() { + expectedException.expect(FcpException::class.java) + command.execute(parameters, null, null) + } + + protected fun requestWithEmptySoneParameterResultsInFcpException() { + parameters.putSingle("Sone", null) + expectedException.expect(FcpException::class.java) + command.execute(parameters, null, null) + } + + protected fun requestWithInvalidSoneParameterResultsInFcpException() { + parameters.putSingle("Sone", "InvalidSoneId") + expectedException.expect(FcpException::class.java) + command.execute(parameters, null, null) + } + + fun requestWithValidRemoteSoneParameterResultsInFcpException() { + parameters.putSingle("Sone", "RemoteSoneId") + whenever(core.getSone("RemoteSoneId")).thenReturn(Optional.of(remoteSone)) + expectedException.expect(FcpException::class.java) + command.execute(parameters, null, null) + } + +}