From 831779f8fcdf131063016644b7fb39baade8527b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 10 Nov 2016 20:52:48 +0100 Subject: [PATCH] Add helper functions for mocking --- .../kotlin/net/pterodactylus/sone/template/RenderFilterTest.kt | 8 ++++---- src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/template/RenderFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/RenderFilterTest.kt index 2d7e6a5..b4a8755 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/RenderFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/RenderFilterTest.kt @@ -5,6 +5,7 @@ import net.pterodactylus.sone.core.Core import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.Profile import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.text.FreemailPart import net.pterodactylus.sone.text.FreenetLinkPart import net.pterodactylus.sone.text.LinkPart @@ -25,7 +26,6 @@ import org.jsoup.nodes.Element import org.jsoup.nodes.TextNode import org.junit.Test import org.mockito.Mockito.`when` -import org.mockito.Mockito.mock import java.net.URLEncoder /** @@ -40,7 +40,7 @@ class RenderFilterTest { private const val POST_ID = "37a06250-6775-4b94-86ff-257ba690953c" } - private val core = mock(Core::class.java) + private val core = mock() private val templateContextFactory = TemplateContextFactory() private val templateContext: TemplateContext private val sone = setupSone(SONE_IDENTITY, "Sone", "First") @@ -162,7 +162,7 @@ class RenderFilterTest { } private fun setupSone(identity: String, name: String?, firstName: String): Sone { - val sone = mock(Sone::class.java) + val sone = mock() `when`(sone.id).thenReturn(identity) `when`(sone.profile).thenReturn(Profile(sone)) `when`(sone.name).thenReturn(name) @@ -186,7 +186,7 @@ class RenderFilterTest { } private fun setupPost(sone: Sone, value: String): Post { - val post = mock(Post::class.java) + val post = mock() `when`(post.id).thenReturn(POST_ID) `when`(post.sone).thenReturn(sone) `when`(post.text).thenReturn(value) diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt b/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt new file mode 100644 index 0000000..ed2f3fc --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt @@ -0,0 +1,5 @@ +package net.pterodactylus.sone.test + +import org.mockito.Mockito + +inline fun mock(): T = Mockito.mock(T::class.java)!! -- 2.7.4