Skip to content

Instantly share code, notes, and snippets.

@jeffypooo
Created February 15, 2019 19:54
Show Gist options
  • Select an option

  • Save jeffypooo/ed983365a965ee186e5f04157d0d4861 to your computer and use it in GitHub Desktop.

Select an option

Save jeffypooo/ed983365a965ee186e5f04157d0d4861 to your computer and use it in GitHub Desktop.
mockito_kotlin verfiy extensions (similar to stub)
import org.mockito.verification.VerificationMode
inline fun <T : Any> T.verify(verification: KVerification<T>.(T) -> Unit) = this.apply {
KVerification(this).verification(this)
}
class KVerification<out T>(private val mock: T) {
fun <R> invoked(mode: VerificationMode? = null, methodCall: T.() -> R): R {
return if (null != mode) {
com.nhaarman.mockito_kotlin.verify(mock, mode).methodCall()
} else {
com.nhaarman.mockito_kotlin.verify(mock).methodCall()
}
}
fun noMoreInteractions() = com.nhaarman.mockito_kotlin.verifyNoMoreInteractions(mock)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment