Skip to content

Commit fc95068

Browse files
committed
Merge branch 'dev' of https://github.com/codeborne/mockito-kotlin into codeborne-dev
2 parents 5105493 + 9238c4c commit fc95068

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ import org.mockito.ArgumentCaptor
2929

3030
inline fun <reified T : Any> argumentCaptor() = ArgumentCaptor.forClass(T::class.java)
3131
inline fun <reified T : Any> capture(captor: ArgumentCaptor<T>): T = captor.capture() ?: createInstance<T>()
32+
inline fun <reified T : Any> capture(noinline consumer: (T) -> Unit): T {
33+
var times = 0
34+
return argThat { if (++times == 1) consumer.invoke(this); true }
35+
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.*
99
class ArgumentCaptorTest {
1010

1111
@Test
12-
fun captor() {
12+
fun explicitCaptor() {
1313
val date: Date = mock()
1414
val time = argumentCaptor<Long>()
1515

@@ -18,4 +18,14 @@ class ArgumentCaptorTest {
1818
verify(date).time = capture(time)
1919
expect(time.value).toBe(5L)
2020
}
21+
22+
@Test
23+
fun implicitCaptor() {
24+
val date: Date = mock()
25+
date.time = 5L
26+
27+
verify(date).time = capture {
28+
expect(it).toBe(5L)
29+
}
30+
}
2131
}

0 commit comments

Comments
 (0)