Skip to content

Commit b665264

Browse files
authored
Merge pull request #122 from nhaarman/inorder-lambda
Add a lambda to inOrder() for easier verification
2 parents b50831b + 59bf311 commit b665264

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fun doThrow(vararg toBeThrown: Throwable): Stubber = Mockito.doThrow(*toBeThrown
7676
fun <T> eq(value: T): T = Mockito.eq(value) ?: value
7777
fun ignoreStubs(vararg mocks: Any): Array<out Any> = Mockito.ignoreStubs(*mocks)!!
7878
fun inOrder(vararg mocks: Any): InOrder = Mockito.inOrder(*mocks)!!
79+
fun inOrder(vararg mocks: Any, evaluation: InOrder.() -> Unit) = Mockito.inOrder(*mocks).evaluation()
7980

8081
inline fun <reified T : Any> isA(): T? = Mockito.isA(T::class.java)
8182
fun <T : Any> isNotNull(): T? = Mockito.isNotNull()

mockito-kotlin/src/test/kotlin/test/MockitoTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package test
2+
23
import com.nhaarman.expect.expect
34
import com.nhaarman.expect.expectErrorWithMessage
45
import com.nhaarman.expect.fail
@@ -177,6 +178,23 @@ class MockitoTest : TestBase() {
177178
}
178179
}
179180

181+
@Test
182+
fun testInOrderWithLambda() {
183+
/* Given */
184+
val a = mock<() -> Unit>()
185+
val b = mock<() -> Unit>()
186+
187+
/* When */
188+
b()
189+
a()
190+
191+
/* Then */
192+
inOrder(a, b) {
193+
verify(b).invoke()
194+
verify(a).invoke()
195+
}
196+
}
197+
180198
@Test
181199
fun testClearInvocations() {
182200
val mock = mock<Methods>().apply {

0 commit comments

Comments
 (0)