Skip to content

Instantly share code, notes, and snippets.

@nekdenis
Last active September 27, 2018 02:05
Show Gist options
  • Save nekdenis/2ee977fb437ba9d8cd6aac8766069bf2 to your computer and use it in GitHub Desktop.
Save nekdenis/2ee977fb437ba9d8cd6aac8766069bf2 to your computer and use it in GitHub Desktop.
My usage of Mockito with Kotlin
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