File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
main/kotlin/com/nhaarman/mockito_kotlin Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -39,9 +39,14 @@ import kotlin.reflect.KClass
3939
4040fun after (millis : Long ) = Mockito .after(millis)
4141
42+ /* * Matches any object, excluding nulls. */
4243inline fun <reified T : Any > any () = Mockito .any(T ::class .java) ? : createInstance<T >()
43- inline fun <reified T : Any ? > anyArray (): Array <T > = Mockito .any(Array <T >::class .java) ? : arrayOf()
44+ /* * Matches anything, including nulls. */
45+ inline fun <reified T : Any > anyOrNull (): T = Mockito .any<T >() ? : createInstance<T >()
46+ /* * Matches any vararg object, including nulls. */
4447inline fun <reified T : Any > anyVararg (): T = Mockito .any<T >() ? : createInstance<T >()
48+ /* * Matches any array of type T. */
49+ inline fun <reified T : Any ? > anyArray (): Array <T > = Mockito .any(Array <T >::class .java) ? : arrayOf()
4550inline fun <reified T : Any > argThat (noinline predicate : T .() -> Boolean ) = Mockito .argThat<T > { it -> (it as T ).predicate() } ? : createInstance(T ::class )
4651inline fun <reified T : Any > argForWhich (noinline predicate : T .() -> Boolean ) = argThat(predicate)
4752
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ interface Methods {
5151 fun string (s : String )
5252 fun closedVararg (vararg c : Closed )
5353 fun throwableClass (t : ThrowableClass )
54+ fun nullableString (s : String? )
5455
5556 fun stringResult (): String
5657}
Original file line number Diff line number Diff line change @@ -116,6 +116,22 @@ class MockitoTest {
116116 }
117117 }
118118
119+ @Test
120+ fun anyNull_neverVerifiesAny () {
121+ mock<Methods >().apply {
122+ nullableString(null )
123+ verify(this , never()).nullableString(any())
124+ }
125+ }
126+
127+ @Test
128+ fun anyNull_verifiesAnyOrNull () {
129+ mock<Methods >().apply {
130+ nullableString(null )
131+ verify(this ).nullableString(anyOrNull())
132+ }
133+ }
134+
119135 @Test
120136 fun anyThrowableWithSingleThrowableConstructor () {
121137 mock<Methods >().apply {
@@ -133,6 +149,7 @@ class MockitoTest {
133149 })
134150 }
135151 }
152+
136153 @Test
137154 fun listArgForWhich () {
138155 mock<Methods >().apply {
You can’t perform that action at this time.
0 commit comments