Add helper functions for mocking
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 10 Nov 2016 19:52:48 +0000 (20:52 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Nov 2016 07:10:00 +0000 (08:10 +0100)
src/test/kotlin/net/pterodactylus/sone/template/RenderFilterTest.kt
src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt [new file with mode: 0644]

index 2d7e6a5..b4a8755 100644 (file)
@@ -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<Core>()
        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>(Sone::class.java)
+               val sone = mock<Sone>()
                `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>(Post::class.java)
+               val post = mock<Post>()
                `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 (file)
index 0000000..ed2f3fc
--- /dev/null
@@ -0,0 +1,5 @@
+package net.pterodactylus.sone.test
+
+import org.mockito.Mockito
+
+inline fun <reified T : Any> mock(): T = Mockito.mock<T>(T::class.java)!!