I'm building a microservice using Micronaut. This particular service depends on a automatically generated client from another service, that I'd like to mock in my component tests.
However I'm unable to mock one of the methods of the apiClient. it's signaute looks like this:
Single<? extends HttpResponse> patchProfile(String userId, UserprofileApiEntity userProfile);
where HttpResponse is from the package io.micronaut.http and Single comes from the package io.reactivex
In my test, I'm trying to mock this endpoint as such:
when(userProfileClientMock.patchProfile(userIdCaptor.capture(), profileCaptor.capture())).thenReturn(Single.just(HttpResponse.ok()));
however I'm getting the error
error: no suitable method found for thenReturn(Single<CAP#1>)
when(userProfileClientMock.patchProfile(userIdCaptor.capture(), profileCaptor.capture())).thenReturn(response);
^
method OngoingStubbing.thenReturn(Single<CAP#2>) is not applicable
(argument mismatch; Single<CAP#1> cannot be converted to Single<CAP#2>)
method OngoingStubbing.thenReturn(Single<CAP#2>,Single<CAP#2>...) is not applicable
(argument mismatch; Single<CAP#1> cannot be converted to Single<CAP#2>)
where CAP#1,CAP#2 are fresh type-variables:
CAP#1 extends HttpResponse from capture of ? extends HttpResponse
CAP#2 extends HttpResponse from capture of ? extends HttpResponse
Note: /home/anders/Documents/minecraft/minecraft.api.public.displaynames/minecraft.api.public.displaynames.server/src/test/java/net/minecraft/api/pub/displaynames/DisplaynamesApiTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
from what I gather it's got something to do with the <? extends . . .> part of the signature, I've successfully mocked different methods from similar apiclients returning stuff like Single<Foo> or Maybe<Bar> unfortunately in this case it does not make sense to change the signature of the client.
I've tried specifying the response single as a variable, explicitly typing it as Single<? extends HttpResponse> and Single<MutableHttpResponse> thinking maybe mockito was confused by type-erasure somehow, but to no avail.
any ideas what might be the cause of this, and how to work around it?
Aucun commentaire:
Enregistrer un commentaire