From: David ‘Bombe’ Roden Date: Thu, 10 Nov 2016 19:52:48 +0000 (+0100) Subject: Add helper functions for mocking X-Git-Tag: 0.9.7^2~457 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=831779f8fcdf131063016644b7fb39baade8527b;p=Sone.git Add helper functions for mocking --- 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)!!