2525
2626package com.nhaarman.mockito_kotlin
2727
28+ import com.nhaarman.mockito_kotlin.createinstance.createInstance
2829import org.mockito.ArgumentCaptor
2930import kotlin.reflect.KClass
3031
@@ -33,21 +34,59 @@ inline fun <reified T : Any> nullableArgumentCaptor(): KArgumentCaptor<T?> = KAr
3334
3435inline fun <reified T : Any > capture (captor : ArgumentCaptor <T >): T = captor.capture() ? : createInstance<T >()
3536
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-
3937class KArgumentCaptor <out T : Any ?>(private val captor : ArgumentCaptor <T >, private val tClass : KClass <* >) {
4038
39+ @Deprecated(" Use lastValue" , ReplaceWith (" lastValue" ))
4140 val value: T
4241 get() = captor.value
4342
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+
4471 val allValues: List <T >
4572 get() = captor.allValues
4673
4774 @Suppress(" UNCHECKED_CAST" )
4875 fun capture (): T = captor.capture() ? : createInstance(tClass) as T
4976}
5077
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+
5190/* *
5291 * This method is deprecated because its behavior differs from the Java behavior.
5392 * 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 {
5897 var times = 0
5998 return argThat { if (++ times == 1 ) consumer.invoke(this ); true }
6099}
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