import com.google.common.base.Optional.of
import net.pterodactylus.sone.core.Core
import net.pterodactylus.sone.data.Post
-import net.pterodactylus.sone.freenet.fcp.FcpException
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import org.hamcrest.MatcherAssert.assertThat
fun `request without text results in fcp exception`() {
parameters.putSingle("Sone", "LocalSoneId")
whenever(core.getSone("LocalSoneId")).thenReturn(Optional.of(localSone))
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
parameters.putSingle("Text", "Test")
parameters.putSingle("Recipient", "InvalidSoneId")
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
import net.pterodactylus.sone.core.Core
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.PostReply
-import net.pterodactylus.sone.freenet.fcp.FcpException
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import org.hamcrest.MatcherAssert.assertThat
@Test
fun `request without post parameter results in fcp exception`() {
addValidLocalSoneParameter()
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
fun `request with invalid post parameter results in fcp exception`() {
addValidLocalSoneParameter()
parameters.putSingle("Post", "InvalidPostId")
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
private fun addValidPostParameter() {
fun `request without text results in fcp exception`() {
addValidLocalSoneParameter()
addValidPostParameter()
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
import com.google.common.base.Optional.of
import net.pterodactylus.sone.core.Core
import net.pterodactylus.sone.data.Post
-import net.pterodactylus.sone.freenet.fcp.FcpException
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Test
-import org.mockito.Mockito
import org.mockito.Mockito.verify
/**
@Test
fun `request with invalid post parameter results in fcp exception`() {
parameters.putSingle("Post", "InvalidPostId")
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
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
+ * Base class for Sone FCP command tests.
*/
abstract class SoneCommandTest {
fun setupCore() {
whenever(core.getSone(anyString())).thenReturn(absent())
whenever(core.getPost(anyString())).thenReturn(absent())
+ whenever(core.getPostReply(anyString())).thenReturn(absent())
+ }
+
+ protected fun executeCommandAndExpectFcpException() {
+ expectedException.expect(FcpException::class.java)
+ command.execute(parameters, null, null)
}
protected fun requestWithoutAnyParameterResultsInFcpException() {
protected fun requestWithEmptySoneParameterResultsInFcpException() {
parameters.putSingle("Sone", null)
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
protected fun requestWithInvalidSoneParameterResultsInFcpException() {
parameters.putSingle("Sone", "InvalidSoneId")
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
fun requestWithValidRemoteSoneParameterResultsInFcpException() {
parameters.putSingle("Sone", "RemoteSoneId")
whenever(core.getSone("RemoteSoneId")).thenReturn(Optional.of(remoteSone))
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
}