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 {
20
20
dependencies {
21
21
compile " org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version "
22
22
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 "
24
24
25
25
/* Tests */
26
26
testCompile " junit:junit:4.12"
Original file line number Diff line number Diff line change @@ -39,10 +39,16 @@ import kotlin.reflect.KClass
39
39
40
40
fun after (millis : Long ) = Mockito .after(millis)
41
41
42
+ /* * Matches any object, excluding nulls. */
42
43
inline 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. */
44
47
inline 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()
45
50
inline 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)
46
52
47
53
fun atLeast (numInvocations : Int ): VerificationMode = Mockito .atLeast(numInvocations)!!
48
54
fun atLeastOnce (): VerificationMode = Mockito .atLeastOnce()!!
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ interface Methods {
51
51
fun string (s : String )
52
52
fun closedVararg (vararg c : Closed )
53
53
fun throwableClass (t : ThrowableClass )
54
+ fun nullableString (s : String? )
54
55
55
56
fun stringResult (): String
56
57
}
Original file line number Diff line number Diff line change @@ -116,6 +116,22 @@ class MockitoTest {
116
116
}
117
117
}
118
118
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
+
119
135
@Test
120
136
fun anyThrowableWithSingleThrowableConstructor () {
121
137
mock<Methods >().apply {
@@ -134,6 +150,16 @@ class MockitoTest {
134
150
}
135
151
}
136
152
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
+
137
163
@Test
138
164
fun atLeastXInvocations () {
139
165
mock<Methods >().apply {
You can’t perform that action at this time.
0 commit comments