Skip to content

Commit f6e4390

Browse files
authored
Merge pull request #253 from nhaarman/check-behavior
Adhere to Mockito.argThat contract in check()
2 parents 6837f30 + 200b4c8 commit f6e4390

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Verification.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,13 @@ If you are trying to verify an argument to be null, use `isNull()`.
241241
If you are using `check` as part of a stubbing, use `argThat` or `argForWhich` instead.
242242
""".trimIndent()
243243
)
244-
predicate(arg)
245-
true
244+
245+
try {
246+
predicate(arg)
247+
true
248+
} catch (e: Error) {
249+
e.printStackTrace()
250+
false
251+
}
246252
} ?: createInstance(T::class)
247253
}

tests/src/test/kotlin/test/MatchersTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ class MatchersTest : TestBase() {
129129
}
130130
}
131131

132+
@Test
133+
fun checkProperlyFails() {
134+
mock<Methods>().apply {
135+
closedList(listOf(Closed(), Closed()))
136+
137+
expectErrorWithMessage("Argument(s) are different!") on {
138+
verify(this).closedList(
139+
check {
140+
expect(it.size).toBe(1)
141+
}
142+
)
143+
}
144+
}
145+
}
146+
132147
@Test
133148
fun checkWithNullArgument_throwsError() {
134149
mock<Methods>().apply {

0 commit comments

Comments
 (0)