Skip to content

Commit

Permalink
Merge pull request #117 from nhaarman/nullable-eq
Browse files Browse the repository at this point in the history
Return passed value instead of trying to create an instance
  • Loading branch information
nhaarman committed Nov 12, 2016
2 parents a831657 + 1eead3e commit 37f1717
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fun doReturn(toBeReturned: Any?, vararg toBeReturnedNext: Any?): Stubber = Mocki
fun doThrow(toBeThrown: KClass<out Throwable>): Stubber = Mockito.doThrow(toBeThrown.java)!!
fun doThrow(vararg toBeThrown: Throwable): Stubber = Mockito.doThrow(*toBeThrown)!!

inline fun <reified T : Any> eq(value: T): T = Mockito.eq(value) ?: createInstance<T>()
fun <T> eq(value: T): T = Mockito.eq(value) ?: value
fun ignoreStubs(vararg mocks: Any): Array<out Any> = Mockito.ignoreStubs(*mocks)!!
fun inOrder(vararg mocks: Any): InOrder = Mockito.inOrder(*mocks)!!

Expand Down Expand Up @@ -138,7 +138,7 @@ fun <T> refEq(value: T, vararg excludeFields: String): T? = Mockito.refEq(value,

fun <T> reset(vararg mocks: T) = Mockito.reset(*mocks)

fun <T> same(value: T): T? = Mockito.same(value)
fun <T> same(value: T): T? = Mockito.same(value) ?: value

inline fun <reified T : Any> spy(): T = Mockito.spy(T::class.java)!!
fun <T> spy(value: T): T = Mockito.spy(value)!!
Expand Down
12 changes: 12 additions & 0 deletions mockito-kotlin/src/test/kotlin/EqTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class EqTest {
expect(result).toNotBeNull()
}

@Test
fun nullArgument() {
/* Given */
val s: String? = null

/* When */
val result = eq(s)

/* Then */
expect(result).toBeNull()
}

private interface MyInterface
private open class MyClass : MyInterface
class ClosedClass
Expand Down

0 comments on commit 37f1717

Please sign in to comment.