File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
main/kotlin/com/nhaarman/mockito_kotlin Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 25
25
26
26
package com.nhaarman.mockito_kotlin
27
27
28
+ import org.mockito.ArgumentCaptor
28
29
import org.mockito.Mockito
29
30
import org.mockito.stubbing.Answer
30
31
import org.mockito.stubbing.Stubber
@@ -55,6 +56,9 @@ fun doNothing() = Mockito.doNothing()
55
56
56
57
fun <T > Stubber.whenever (mock : T ) = `when `(mock)
57
58
59
+ inline fun <reified T : Any > argumentCaptor () = ArgumentCaptor .forClass(T ::class .java)
60
+ inline fun <reified T : Any > capture (captor : ArgumentCaptor <T >): T = captor.capture() ? : createInstance<T >()
61
+
58
62
inline fun <reified T : Any > eq (value : T ) = Mockito .eq(value) ? : createInstance<T >()
59
63
inline fun <reified T : Any > anyArray (): Array <T > = Mockito .any(Array <T >::class .java) ? : arrayOf()
60
64
inline fun <reified T : Any > any () = Mockito .any(T ::class .java) ? : createInstance<T >()
Original file line number Diff line number Diff line change
1
+ import com.nhaarman.mockito_kotlin.argumentCaptor
2
+ import com.nhaarman.mockito_kotlin.mock
3
+ import com.nhaarman.mockito_kotlin.verify
4
+ import com.nhaarman.expect.expect
5
+ import com.nhaarman.mockito_kotlin.capture
6
+ import org.junit.Test
7
+ import java.util.*
8
+
9
+ class ArgumentCaptorTest {
10
+ @Test
11
+ fun captor () {
12
+ val date: Date = mock()
13
+ val time = argumentCaptor<Long >()
14
+
15
+ date.time = 5L
16
+
17
+ verify(date).time = capture(time)
18
+ expect(time.value).toBe(5L )
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments