Last active
September 27, 2018 02:05
-
-
Save nekdenis/2ee977fb437ba9d8cd6aac8766069bf2 to your computer and use it in GitHub Desktop.
My usage of Mockito with Kotlin
This file contains 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
package com.sample | |
import org.mockito.Mockito | |
//wrappers: | |
inline fun <reified T : Any> mock(): T = Mockito.mock(T::class.java) | |
inline fun <reified T : Any> mock(mocking: T.() -> Unit): T = Mockito.mock(T::class.java).apply { mocking() } | |
fun <T> whenCall(methodCall: T) = Mockito.`when`(methodCall) | |
//usage sample: | |
val baseActivity: BaseActivity = mock() | |
val baseActivityHolder: ContextWrapper = mock { | |
whenCall(baseContext).thenReturn(baseActivity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment