File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
mockito-kotlin/src/main/kotlin/org/mockito/kotlin
tests/src/test/kotlin/test Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ import org.mockito.kotlin.internal.valueClassInnerClass
3737
3838/* * Matches an argument that is equal to the given value. */
3939inline fun <reified T : Any ? > eq (value : T ): T {
40- if (T ::class .isValue) return eqValueClass(value)
40+ if (value != null && T ::class .isValue) return eqValueClass(value)
4141
4242 return ArgumentMatchers .eq(value) ? : value
4343}
@@ -87,10 +87,10 @@ inline fun <reified T> anyValueClass(): T {
8787}
8888
8989/* * Matches an argument that is equal to the given Kotlin value class value. */
90- inline fun <reified T > eqValueClass (value : T ): T {
90+ inline fun <reified T : Any > eqValueClass (value : T ): T {
9191 require(value::class .isValue) { " ${value::class .qualifiedName} is not a value class." }
9292
93- val unboxed = value? .unboxValueClass()
93+ val unboxed = value.unboxValueClass()
9494 val matcher = AdditionalMatchers .or (ArgumentMatchers .eq(value), ArgumentMatchers .eq(unboxed))
9595
9696 return (matcher ? : unboxed).toKotlinType(T ::class )
Original file line number Diff line number Diff line change @@ -672,6 +672,24 @@ class MatchersTest : TestBase() {
672672 verify(this ).nestedValueClass(eq(nestedValueClass))
673673 }
674674 }
675+
676+ @Test
677+ fun eqNullableValueClass_nullValue () {
678+ val valueClass = null as ValueClass ?
679+ mock<SynchronousFunctions >().apply {
680+ nullableValueClass(valueClass)
681+ verify(this ).nullableValueClass(eq(valueClass))
682+ }
683+ }
684+
685+ @Test
686+ fun eqNullableLongValueClass_nullValue () {
687+ val longValueClass = null as LongValueClass ?
688+ mock<SynchronousFunctions >().apply {
689+ nullableLongValueClass(longValueClass)
690+ verify(this ).nullableLongValueClass(eq(longValueClass))
691+ }
692+ }
675693 }
676694
677695 class OtherMatchersTest {
You can’t perform that action at this time.
0 commit comments