File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
main/kotlin/com/nhaarman/mockitokotlin2 Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -193,7 +193,7 @@ inline fun <reified T : Any> mock(s: MockSettings): T = Mockito.mock(T::class.ja
193
193
class KStubbing <out T >(private val mock : T ) {
194
194
fun <R > on (methodCall : R ) = Mockito .`when `(methodCall)
195
195
196
- fun <R : Any > onGeneric (methodCall : T .() -> R , c : KClass <R >): OngoingStubbing <R > {
196
+ fun <R : Any > onGeneric (methodCall : T .() -> R ? , c : KClass <R >): OngoingStubbing <R > {
197
197
val r = try {
198
198
mock.methodCall()
199
199
} catch (e: NullPointerException ) {
@@ -207,7 +207,7 @@ class KStubbing<out T>(private val mock: T) {
207
207
return Mockito .`when `(r)
208
208
}
209
209
210
- inline fun <reified R : Any > onGeneric (noinline methodCall : T .() -> R ): OngoingStubbing <R > {
210
+ inline fun <reified R : Any > onGeneric (noinline methodCall : T .() -> R ? ): OngoingStubbing <R > {
211
211
return onGeneric(methodCall, R ::class )
212
212
}
213
213
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ abstract class ThrowingConstructor {
77
77
78
78
interface GenericMethods <T > {
79
79
fun genericMethod (): T
80
+ fun nullableReturnType (): T ?
80
81
}
81
82
82
83
class ThrowableClass (cause : Throwable ) : Throwable(cause)
Original file line number Diff line number Diff line change @@ -1004,6 +1004,15 @@ class MockitoTest : TestBase() {
1004
1004
expect(mock.genericMethod()).toBe(2 )
1005
1005
}
1006
1006
1007
+ @Test
1008
+ fun doReturn_withGenericNullableReturnType_onGeneric () {
1009
+ val m = mock<GenericMethods <String >> {
1010
+ onGeneric { nullableReturnType() } doReturn " Test"
1011
+ }
1012
+
1013
+ expect(m.nullableReturnType()).toBe(" Test" )
1014
+ }
1015
+
1007
1016
@Test
1008
1017
fun isA_withNonNullableString () {
1009
1018
mock<Methods >().apply {
You can’t perform that action at this time.
0 commit comments