File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed
main/kotlin/com/nhaarman/mockito_kotlin Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ repositories {
2020dependencies {
2121 compile " org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version "
2222 compile " org.jetbrains.kotlin:kotlin-reflect:$kotlin_version "
23- compile " org.mockito:mockito-core:2.1.0-beta.125 "
23+ compile " org.mockito:mockito-core:2.1.0-RC.1 "
2424
2525 /* Tests */
2626 testCompile " junit:junit:4.12"
Original file line number Diff line number Diff line change @@ -39,10 +39,16 @@ 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 )
51+ inline fun <reified T : Any > argForWhich (noinline predicate : T .() -> Boolean ) = argThat(predicate)
4652
4753fun atLeast (numInvocations : Int ): VerificationMode = Mockito .atLeast(numInvocations)!!
4854fun atLeastOnce (): VerificationMode = Mockito .atLeastOnce()!!
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 {
@@ -134,6 +150,16 @@ class MockitoTest {
134150 }
135151 }
136152
153+ @Test
154+ fun listArgForWhich () {
155+ mock<Methods >().apply {
156+ closedList(listOf (Closed (), Closed ()))
157+ verify(this ).closedList(argForWhich {
158+ size == 2
159+ })
160+ }
161+ }
162+
137163 @Test
138164 fun atLeastXInvocations () {
139165 mock<Methods >().apply {
You can’t perform that action at this time.
0 commit comments