Skip to content

Commit 9a3b7de

Browse files
committed
Introduce argForWhich() as an alias for argThat()
1 parent 8d53bad commit 9a3b7de

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-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
@@ -43,6 +43,7 @@ inline fun <reified T : Any> any() = Mockito.any(T::class.java) ?: createInstanc
4343
inline fun <reified T : Any?> anyArray(): Array<T> = Mockito.any(Array<T>::class.java) ?: arrayOf()
4444
inline fun <reified T : Any> anyVararg(): T = Mockito.any<T>() ?: createInstance<T>()
4545
inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean) = Mockito.argThat<T> { it -> (it as T).predicate() } ?: createInstance(T::class)
46+
inline fun <reified T : Any> argForWhich(noinline predicate: T.() -> Boolean) = argThat(predicate)
4647

4748
fun atLeast(numInvocations: Int): VerificationMode = Mockito.atLeast(numInvocations)!!
4849
fun atLeastOnce(): VerificationMode = Mockito.atLeastOnce()!!

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ class MockitoTest {
133133
})
134134
}
135135
}
136+
@Test
137+
fun listArgForWhich() {
138+
mock<Methods>().apply {
139+
closedList(listOf(Closed(), Closed()))
140+
verify(this).closedList(argForWhich {
141+
size == 2
142+
})
143+
}
144+
}
136145

137146
@Test
138147
fun atLeastXInvocations() {

0 commit comments

Comments
 (0)