Skip to content

Commit

Permalink
Add a lambda to inOrder() for easier verification
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Nov 15, 2016
1 parent b50831b commit 59bf311
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fun doThrow(vararg toBeThrown: Throwable): Stubber = Mockito.doThrow(*toBeThrown
fun <T> eq(value: T): T = Mockito.eq(value) ?: value
fun ignoreStubs(vararg mocks: Any): Array<out Any> = Mockito.ignoreStubs(*mocks)!!
fun inOrder(vararg mocks: Any): InOrder = Mockito.inOrder(*mocks)!!
fun inOrder(vararg mocks: Any, evaluation: InOrder.() -> Unit) = Mockito.inOrder(*mocks).evaluation()

inline fun <reified T : Any> isA(): T? = Mockito.isA(T::class.java)
fun <T : Any> isNotNull(): T? = Mockito.isNotNull()
Expand Down
18 changes: 18 additions & 0 deletions mockito-kotlin/src/test/kotlin/test/MockitoTest.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package test

import com.nhaarman.expect.expect
import com.nhaarman.expect.expectErrorWithMessage
import com.nhaarman.expect.fail
Expand Down Expand Up @@ -177,6 +178,23 @@ class MockitoTest : TestBase() {
}
}

@Test
fun testInOrderWithLambda() {
/* Given */
val a = mock<() -> Unit>()
val b = mock<() -> Unit>()

/* When */
b()
a()

/* Then */
inOrder(a, b) {
verify(b).invoke()
verify(a).invoke()
}
}

@Test
fun testClearInvocations() {
val mock = mock<Methods>().apply {
Expand Down

0 comments on commit 59bf311

Please sign in to comment.