25
25
26
26
package com.nhaarman.mockito_kotlin
27
27
28
+ import com.nhaarman.mockito_kotlin.createinstance.createInstance
28
29
import org.mockito.ArgumentCaptor
29
30
import kotlin.reflect.KClass
30
31
@@ -33,21 +34,59 @@ inline fun <reified T : Any> nullableArgumentCaptor(): KArgumentCaptor<T?> = KAr
33
34
34
35
inline fun <reified T : Any > capture (captor : ArgumentCaptor <T >): T = captor.capture() ? : createInstance<T >()
35
36
36
- @Deprecated(" Use captor.capture() instead." , ReplaceWith (" captor.capture()" ), DeprecationLevel .ERROR )
37
- inline fun <reified T : Any > capture (captor : KArgumentCaptor <T >): T = captor.capture()
38
-
39
37
class KArgumentCaptor <out T : Any ?>(private val captor : ArgumentCaptor <T >, private val tClass : KClass <* >) {
40
38
39
+ @Deprecated(" Use lastValue" , ReplaceWith (" lastValue" ))
41
40
val value: T
42
41
get() = captor.value
43
42
43
+ /* *
44
+ * The first captured value of the argument.
45
+ * @throws IndexOutOfBoundsException if the value is not available.
46
+ */
47
+ val firstValue: T
48
+ get() = captor.firstValue
49
+
50
+ /* *
51
+ * The second captured value of the argument.
52
+ * @throws IndexOutOfBoundsException if the value is not available.
53
+ */
54
+ val secondValue: T
55
+ get() = captor.secondValue
56
+
57
+ /* *
58
+ * The third captured value of the argument.
59
+ * @throws IndexOutOfBoundsException if the value is not available.
60
+ */
61
+ val thirdValue: T
62
+ get() = captor.thirdValue
63
+
64
+ /* *
65
+ * The last captured value of the argument.
66
+ * @throws IndexOutOfBoundsException if the value is not available.
67
+ */
68
+ val lastValue: T
69
+ get() = captor.lastValue
70
+
44
71
val allValues: List <T >
45
72
get() = captor.allValues
46
73
47
74
@Suppress(" UNCHECKED_CAST" )
48
75
fun capture (): T = captor.capture() ? : createInstance(tClass) as T
49
76
}
50
77
78
+ val <T > ArgumentCaptor <T >.firstValue: T
79
+ get() = allValues[0 ]
80
+
81
+ val <T > ArgumentCaptor <T >.secondValue: T
82
+ get() = allValues[1 ]
83
+
84
+ val <T > ArgumentCaptor <T >.thirdValue: T
85
+ get() = allValues[2 ]
86
+
87
+ val <T > ArgumentCaptor <T >.lastValue: T
88
+ get() = allValues.last()
89
+
51
90
/* *
52
91
* This method is deprecated because its behavior differs from the Java behavior.
53
92
* Instead, use [argumentCaptor] in the traditional way, or use one of
@@ -58,3 +97,7 @@ inline fun <reified T : Any> capture(noinline consumer: (T) -> Unit): T {
58
97
var times = 0
59
98
return argThat { if (++ times == 1 ) consumer.invoke(this ); true }
60
99
}
100
+
101
+ @Deprecated(" Use captor.capture() instead." , ReplaceWith (" captor.capture()" ), DeprecationLevel .ERROR )
102
+ inline fun <reified T : Any > capture (captor : KArgumentCaptor <T >): T = captor.capture()
103
+
0 commit comments