Skip to content

Commit f4f4774

Browse files
authored
Update to Mockito 3 and bump major version (#417)
Mockito 3 requires Java 8 minimum and the ArgumentMatchers reject null by default. Therefore, matchers will no longer work if null is passed in (which is better for Kotlin since Kotlin is non-nullable by default).
1 parent 8031bd6 commit f4f4774

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

mockito-kotlin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2626
compileOnly 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
2727

28-
compile "org.mockito:mockito-core:2.23.0"
28+
compile "org.mockito:mockito-core:3.8.0"
2929

3030
testCompile 'junit:junit:4.12'
3131
testCompile 'com.nhaarman:expect.kt:1.0.0'

mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Matchers.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@ package org.mockito.kotlin
2727

2828
import org.mockito.kotlin.internal.createInstance
2929
import org.mockito.ArgumentMatcher
30-
import org.mockito.Mockito
30+
import org.mockito.ArgumentMatchers
3131

3232
/** Object argument that is equal to the given value. */
3333
fun <T> eq(value: T): T {
34-
return Mockito.eq(value) ?: value
34+
return ArgumentMatchers.eq(value) ?: value
3535
}
3636

3737
/** Object argument that is the same as the given value. */
3838
fun <T> same(value: T): T {
39-
return Mockito.same(value) ?: value
39+
return ArgumentMatchers.same(value) ?: value
4040
}
4141

4242
/** Matches any object, excluding nulls. */
4343
inline fun <reified T : Any> any(): T {
44-
return Mockito.any(T::class.java) ?: createInstance()
44+
return ArgumentMatchers.any(T::class.java) ?: createInstance()
4545
}
4646

4747
/** Matches anything, including nulls. */
4848
inline fun <reified T : Any> anyOrNull(): T {
49-
return Mockito.any<T>() ?: createInstance()
49+
return ArgumentMatchers.any<T>() ?: createInstance()
5050
}
5151

5252
/** Matches any vararg object, including nulls. */
5353
inline fun <reified T : Any> anyVararg(): T {
54-
return Mockito.any<T>() ?: createInstance()
54+
return ArgumentMatchers.any<T>() ?: createInstance()
5555
}
5656

5757
/** Matches any array of type T. */
5858
inline fun <reified T : Any?> anyArray(): Array<T> {
59-
return Mockito.any(Array<T>::class.java) ?: arrayOf()
59+
return ArgumentMatchers.any(Array<T>::class.java) ?: arrayOf()
6060
}
6161

6262
/**
@@ -66,7 +66,7 @@ inline fun <reified T : Any?> anyArray(): Array<T> {
6666
* @param predicate An extension function on [T] that returns `true` when a [T] matches the predicate.
6767
*/
6868
inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean): T {
69-
return Mockito.argThat { arg: T? -> arg?.predicate() ?: false } ?: createInstance(
69+
return ArgumentMatchers.argThat { arg: T? -> arg?.predicate() ?: false } ?: createInstance(
7070
T::class
7171
)
7272
}
@@ -78,7 +78,7 @@ inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean): T {
7878
* @param matcher The ArgumentMatcher on [T] to be registered.
7979
*/
8080
inline fun <reified T : Any> argThat(matcher: ArgumentMatcher<T>): T {
81-
return Mockito.argThat(matcher) ?: createInstance()
81+
return ArgumentMatchers.argThat(matcher) ?: createInstance()
8282
}
8383

8484
/**
@@ -107,33 +107,33 @@ inline fun <reified T : Any> argWhere(noinline predicate: (T) -> Boolean): T {
107107
* Argument that implements the given class.
108108
*/
109109
inline fun <reified T : Any> isA(): T {
110-
return Mockito.isA(T::class.java) ?: createInstance()
110+
return ArgumentMatchers.isA(T::class.java) ?: createInstance()
111111
}
112112

113113
/**
114114
* `null` argument.
115115
*/
116-
fun <T : Any> isNull(): T? = Mockito.isNull()
116+
fun <T : Any> isNull(): T? = ArgumentMatchers.isNull()
117117

118118
/**
119119
* Not `null` argument.
120120
*/
121121
fun <T : Any> isNotNull(): T? {
122-
return Mockito.isNotNull()
122+
return ArgumentMatchers.isNotNull()
123123
}
124124

125125
/**
126126
* Not `null` argument.
127127
*/
128128
fun <T : Any> notNull(): T? {
129-
return Mockito.notNull()
129+
return ArgumentMatchers.notNull()
130130
}
131131

132132
/**
133133
* Object argument that is reflection-equal to the given value with support for excluding
134134
* selected fields from a class.
135135
*/
136136
inline fun <reified T : Any> refEq(value: T, vararg excludeFields: String): T {
137-
return Mockito.refEq<T>(value, *excludeFields) ?: createInstance()
137+
return ArgumentMatchers.refEq<T>(value, *excludeFields) ?: createInstance()
138138
}
139139

0 commit comments

Comments
 (0)