Skip to content

Commit 59eb199

Browse files
committed
add argThat(ArgumentMatcher<T>) function
1 parent a0f7875 commit 59eb199

File tree

1 file changed

+11
-0
lines changed
  • mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2

1 file changed

+11
-0
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Matchers.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.nhaarman.mockitokotlin2
2727

2828
import com.nhaarman.mockitokotlin2.internal.createInstance
29+
import org.mockito.ArgumentMatcher
2930
import org.mockito.Mockito
3031

3132
/** Object argument that is equal to the given value. */
@@ -70,6 +71,16 @@ inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean): T {
7071
)
7172
}
7273

74+
/**
75+
* Registers a custom ArgumentMatcher. The original Mockito function registers the matcher and returns null,
76+
* here the required type is returned.
77+
*
78+
* @param matcher The ArgumentMatcher on [T] to be registered.
79+
*/
80+
inline fun <reified T : Any> argThat(matcher: ArgumentMatcher<T>): T {
81+
return Mockito.argThat(matcher) ?: createInstance()
82+
}
83+
7384
/**
7485
* Alias for [argThat].
7586
*

0 commit comments

Comments
 (0)