From 201ccb643923d7771cba32453279faf0344018f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 15 Jan 2017 10:12:04 +0100 Subject: [PATCH] Add unit test for like post command --- .../pterodactylus/sone/fcp/LikePostCommandTest.kt | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt new file mode 100644 index 0000000..f88e138 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt @@ -0,0 +1,77 @@ +package net.pterodactylus.sone.fcp + +import net.pterodactylus.sone.core.Core +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.freenet.fcp.FcpException +import net.pterodactylus.sone.test.asOptional +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.Before +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [LikePostCommand]. + */ +class LikePostCommandTest : SoneCommandTest() { + + private val post = createPost("PostId", mock(), null, 1000, "Text") + + override fun createCommand(core: Core) = LikePostCommand(core) + + @Before + fun setupPostAndSones() { + whenever(core.getPost("PostId")).thenReturn(post.asOptional()) + whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional()) + whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional()) + } + + @Test + fun `request without parameters results in FCP exception`() { + requestWithoutAnyParameterResultsInFcpException() + } + + @Test + fun `request with invalid post id results in FCP exception`() { + parameters += "Post" to "InvalidPostId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with missing local sone results in FCP exception`() { + parameters += "Post" to "PostId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with invalid sone results in FCP exception`() { + parameters += "Post" to "PostId" + parameters += "Sone" to "InvalidSoneId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with valid remote sone results in FCP exception`() { + parameters += "Post" to "PostId" + parameters += "Sone" to "RemoteSoneId" + expectedException.expect(FcpException::class.java) + command.execute(parameters) + } + + @Test + fun `request with valid parameters adds post to liked posts for sone`() { + whenever(core.getLikes(post)).thenReturn(setOf(mock(), mock(), mock())) + parameters += "Post" to "PostId" + parameters += "Sone" to "LocalSoneId" + val replyParameters = command.execute(parameters).replyParameters + assertThat(replyParameters["Message"], equalTo("PostLiked")) + assertThat(replyParameters["LikeCount"], equalTo("3")) + verify(localSone).addLikedPostId("PostId") + } + +} -- 2.7.4