Last active
May 10, 2019 20:10
-
-
Save ademar111190/4b5627134f034b427d3d50bad7a8d7b4 to your computer and use it in GitHub Desktop.
Some mockito extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mockito.* | |
import org.mockito.stubbing.OngoingStubbing | |
inline fun <reified T> mock() = Mockito.mock(T::class.java) as T | |
inline fun <reified T> mock(body: T.() -> Unit) = (Mockito.mock(T::class.java) as T).apply { | |
body() | |
} | |
@CheckReturnValue | |
fun <T> whenever(methodCall: T): OngoingStubbing<T> = Mockito.`when`(methodCall) | |
inline fun <reified T> anyOfType() = Mockito.any(T::class.java) ?: uninitialized() | |
@Suppress("UNCHECKED_CAST") | |
fun <T> uninitialized(): T = null as T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment