From 6cdcdf75cbc0b5341705f55f7b6a33073405732b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 8 Jan 2017 00:54:05 +0100 Subject: [PATCH] Extract method and move it to test base class --- .../pterodactylus/sone/fcp/CreatePostCommandTest.kt | 7 ++----- .../pterodactylus/sone/fcp/CreateReplyCommandTest.kt | 10 +++------- .../pterodactylus/sone/fcp/DeletePostCommandTest.kt | 5 +---- .../net/pterodactylus/sone/fcp/SoneCommandTest.kt | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt index 75e238e..98b0a67 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/CreatePostCommandTest.kt @@ -5,7 +5,6 @@ import com.google.common.base.Optional.absent 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 @@ -49,8 +48,7 @@ class CreatePostCommandTest : SoneCommandTest() { 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 @@ -71,8 +69,7 @@ class CreatePostCommandTest : SoneCommandTest() { 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 diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt index 6d39083..1269272 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt @@ -4,7 +4,6 @@ import com.google.common.base.Optional.of 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 @@ -53,16 +52,14 @@ class CreateReplyCommandTest : SoneCommandTest() { @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() { @@ -74,8 +71,7 @@ class CreateReplyCommandTest : SoneCommandTest() { fun `request without text results in fcp exception`() { addValidLocalSoneParameter() addValidPostParameter() - expectedException.expect(FcpException::class.java) - command.execute(parameters, null, null) + executeCommandAndExpectFcpException() } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt index 4a23602..71e6eee 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt @@ -3,13 +3,11 @@ package net.pterodactylus.sone.fcp 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 /** @@ -34,8 +32,7 @@ class DeletePostCommandTest : SoneCommandTest() { @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 diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt index 2f2de5c..b02aa9e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt @@ -5,19 +5,16 @@ 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 + * Base class for Sone FCP command tests. */ abstract class SoneCommandTest { @@ -38,6 +35,12 @@ 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() { @@ -47,21 +50,18 @@ abstract class SoneCommandTest { 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() } } -- 2.7.4