Skip to content

Commit acde82f

Browse files
ghostbuster91nhaarman
authored andcommitted
Change isA method to return instance of T
1 parent 72279be commit acde82f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fun ignoreStubs(vararg mocks: Any): Array<out Any> = Mockito.ignoreStubs(*mocks)
7878
fun inOrder(vararg mocks: Any): InOrder = Mockito.inOrder(*mocks)!!
7979
fun inOrder(vararg mocks: Any, evaluation: InOrder.() -> Unit) = Mockito.inOrder(*mocks).evaluation()
8080

81-
inline fun <reified T : Any> isA(): T? = Mockito.isA(T::class.java)
81+
inline fun <reified T : Any> isA(): T = Mockito.isA(T::class.java) ?: createInstance<T>()
8282
fun <T : Any> isNotNull(): T? = Mockito.isNotNull()
8383
fun <T : Any> isNull(): T? = Mockito.isNull()
8484

mockito-kotlin/src/test/kotlin/test/MockitoTest.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,19 @@ class MockitoTest : TestBase() {
492492
/* Then */
493493
expect(mock.genericMethod()).toBe(2)
494494
}
495-
}
495+
496+
@Test
497+
fun isA_withNonNullableString() {
498+
mock<Methods>().apply {
499+
string("")
500+
verify(this).string(isA<String>())
501+
}
502+
}
503+
@Test
504+
fun isA_withNullableString() {
505+
mock<Methods>().apply {
506+
nullableString("")
507+
verify(this).nullableString(isA<String>())
508+
}
509+
}
510+
}

0 commit comments

Comments
 (0)