diff options
author | Niek Haarman <haarman.niek@gmail.com> | 2019-06-19 20:32:51 +0200 |
---|---|---|
committer | Niek Haarman <haarman.niek@gmail.com> | 2019-06-19 20:32:51 +0200 |
commit | 84783a503221b19cef538b64cced9bc5eedc7901 (patch) | |
tree | eedb2fba09fc5edbe106b835302814f7e74d70ac | |
parent | 294c8cc0396565e87e5046326ef45d086ca4c094 (diff) | |
parent | 76198eab935700356643fd8b8d417aec9b09bee4 (diff) | |
download | mockito-kotlin-84783a503221b19cef538b64cced9bc5eedc7901.tar.gz |
Merge branch '2.x' into unlimitedsola-2.x
-rw-r--r-- | mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Matchers.kt | 4 | ||||
-rw-r--r-- | tests/src/test/kotlin/test/MatchersTest.kt | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Matchers.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Matchers.kt index cc21191..1d89902 100644 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Matchers.kt +++ b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Matchers.kt @@ -133,7 +133,7 @@ fun <T : Any> notNull(): T? { * Object argument that is reflection-equal to the given value with support for excluding * selected fields from a class. */ -fun <T> refEq(value: T, vararg excludeFields: String): T? { - return Mockito.refEq(value, *excludeFields) +inline fun <reified T : Any> refEq(value: T, vararg excludeFields: String): T { + return Mockito.refEq<T>(value, *excludeFields) ?: createInstance() } diff --git a/tests/src/test/kotlin/test/MatchersTest.kt b/tests/src/test/kotlin/test/MatchersTest.kt index 8b3a87f..a17fe35 100644 --- a/tests/src/test/kotlin/test/MatchersTest.kt +++ b/tests/src/test/kotlin/test/MatchersTest.kt @@ -228,6 +228,19 @@ class MatchersTest : TestBase() { expect(t.varargBooleanResult("a", "b", "c")).toBe(false) } + /** https://github.com/nhaarman/mockito-kotlin/issues/328 */ + @Test + fun testRefEqForNonNullableParameter() { + mock<Methods>().apply { + /* When */ + val array = intArrayOf(2, 3) + intArray(array) + + /* Then */ + verify(this).intArray(refEq(array)) + } + } + /** * a VarargMatcher implementation for varargs of type [T] that will answer with type [R] if any of the var args * matched. Needs to keep state between matching invocations. |