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
193193class KStubbing <out T >(private val mock : T ) {
194194 fun <R > on (methodCall : R ) = Mockito .`when `(methodCall)
195195
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 > {
197197 val r = try {
198198 mock.methodCall()
199199 } catch (e: NullPointerException ) {
@@ -207,7 +207,7 @@ class KStubbing<out T>(private val mock: T) {
207207 return Mockito .`when `(r)
208208 }
209209
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 > {
211211 return onGeneric(methodCall, R ::class )
212212 }
213213
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ abstract class ThrowingConstructor {
7777
7878interface GenericMethods <T > {
7979 fun genericMethod (): T
80+ fun nullableReturnType (): T ?
8081}
8182
8283class ThrowableClass (cause : Throwable ) : Throwable(cause)
Original file line number Diff line number Diff line change @@ -1004,6 +1004,15 @@ class MockitoTest : TestBase() {
10041004 expect(mock.genericMethod()).toBe(2 )
10051005 }
10061006
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+
10071016 @Test
10081017 fun isA_withNonNullableString () {
10091018 mock<Methods >().apply {
You can’t perform that action at this time.
0 commit comments