File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
main/kotlin/com/nhaarman/mockito_kotlin Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ fun <T> Stubber.whenever(mock: T) = `when`(mock)
58
58
59
59
inline fun <reified T : Any > argumentCaptor () = ArgumentCaptor .forClass(T ::class .java)
60
60
inline fun <reified T : Any > capture (captor : ArgumentCaptor <T >): T = captor.capture() ? : createInstance<T >()
61
+ inline fun <reified T : Any > capture (noinline consumer : (T ) -> Unit ): T {
62
+ var times = 0
63
+ return argThat { if (++ times == 1 ) consumer.invoke(this ); true }
64
+ }
61
65
62
66
inline fun <reified T : Any > eq (value : T ) = Mockito .eq(value) ? : createInstance<T >()
63
67
inline fun <reified T : Any > anyArray (): Array <T > = Mockito .any(Array <T >::class .java) ? : arrayOf()
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import java.util.*
8
8
9
9
class ArgumentCaptorTest {
10
10
@Test
11
- fun captor () {
11
+ fun explicitCaptor () {
12
12
val date: Date = mock()
13
13
val time = argumentCaptor<Long >()
14
14
@@ -17,4 +17,14 @@ class ArgumentCaptorTest {
17
17
verify(date).time = capture(time)
18
18
expect(time.value).toBe(5L )
19
19
}
20
+
21
+ @Test
22
+ fun implicitCaptor () {
23
+ val date: Date = mock()
24
+ date.time = 5L
25
+
26
+ verify(date).time = capture {
27
+ expect(it).toBe(5L )
28
+ }
29
+ }
20
30
}
You can’t perform that action at this time.
0 commit comments