Skip to content

Commit 76be5d0

Browse files
committed
add more missing Mockito methods, especially to be used with spies
1 parent 7cafd23 commit 76be5d0

File tree

1 file changed

+12
-0
lines changed
  • mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin

1 file changed

+12
-0
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.mockito.verification.VerificationMode
3030
import kotlin.reflect.KClass
3131

3232
inline fun <reified T : Any> mock() = Mockito.mock(T::class.java)
33+
inline fun <reified T : Any> mock(defaultAnswer: Answer<Any>) = Mockito.mock(T::class.java, defaultAnswer)
3334
fun <T : Any> spy(value: T) = Mockito.spy(value)
3435

3536
fun <T> whenever(methodCall: T) = Mockito.`when`(methodCall)
@@ -40,6 +41,17 @@ fun <T> reset(mock: T) = Mockito.reset(mock)
4041

4142
fun inOrder(vararg value: Any) = Mockito.inOrder(*value)
4243
fun never() = Mockito.never()
44+
fun times(numInvocations: Int) = Mockito.times(numInvocations)
45+
fun atLeast(numInvocations: Int) = Mockito.atLeast(numInvocations)
46+
fun atLeastOnce() = Mockito.atLeastOnce()
47+
48+
fun doReturn(value: Any) = Mockito.doReturn(value)
49+
fun doThrow(throwable: Throwable) = Mockito.doThrow(throwable)
50+
fun <T> doAnswer(answer: Answer<T>) = Mockito.doAnswer(answer)
51+
fun doCallRealMethod() = Mockito.doCallRealMethod()
52+
fun doNothing() = Mockito.doNothing()
53+
54+
fun <T> Stubber.whenever(mock: T) = `when`(mock)
4355

4456
inline fun <reified T : Any> eq(value: T) = Mockito.eq(value) ?: createInstance<T>()
4557
inline fun <reified T : Any> anyArray(): Array<T> = Mockito.any(Array<T>::class.java) ?: arrayOf()

0 commit comments

Comments
 (0)