Skip to content

Commit 76198ea

Browse files
committed
Merge branch 'pablisco-2.x' into 2.x
2 parents efccc0b + fa6a72c commit 76198ea

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fun <T : Any> notNull(): T? {
133133
* Object argument that is reflection-equal to the given value with support for excluding
134134
* selected fields from a class.
135135
*/
136-
fun <T> refEq(value: T, vararg excludeFields: String): T? {
137-
return Mockito.refEq(value, *excludeFields)
136+
inline fun <reified T : Any> refEq(value: T, vararg excludeFields: String): T {
137+
return Mockito.refEq<T>(value, *excludeFields) ?: createInstance()
138138
}
139139

tests/src/test/kotlin/test/MatchersTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ class MatchersTest : TestBase() {
228228
expect(t.varargBooleanResult("a", "b", "c")).toBe(false)
229229
}
230230

231+
/** https://github.com/nhaarman/mockito-kotlin/issues/328 */
232+
@Test
233+
fun testRefEqForNonNullableParameter() {
234+
mock<Methods>().apply {
235+
/* When */
236+
val array = intArrayOf(2, 3)
237+
intArray(array)
238+
239+
/* Then */
240+
verify(this).intArray(refEq(array))
241+
}
242+
}
243+
231244
/**
232245
* a VarargMatcher implementation for varargs of type [T] that will answer with type [R] if any of the var args
233246
* matched. Needs to keep state between matching invocations.

0 commit comments

Comments
 (0)