Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return passed value instead of trying to create an instance #117

Merged
merged 1 commit into from
Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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