-
-
Save albodelu/1b692a0874b52a6998b84118c249d328 to your computer and use it in GitHub Desktop.
My usage of Mockito with Kotlin
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
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