java mockito respose_无法模拟clientMethod返回single<?使用Mockito扩展httpResponse>

我正在使用Micronaut构建微服务。这个特定的服务依赖于从另一个服务自动生成的客户机,我想在我的组件测试中模拟它。

然而,我无法模仿其中一个方法的顶端。签名人看起来像这样:

Single extends HttpResponse> patchProfile(String userId, UserprofileApiEntity userProfile);

哪里

HttpResponse

是从包裹里

io.micronaut.http

Single

来自包裹

io.reactivex

在我的测试中,我尝试这样模拟这个端点:

when(userProfileClientMock.patchProfile(userIdCaptor.capture(), profileCaptor.capture())).thenReturn(Single.just(HttpResponse.ok()));

但是我得到了错误

error: no suitable method found for thenReturn(Single)

when(userProfileClientMock.patchProfile(userIdCaptor.capture(), profileCaptor.capture())).thenReturn(response);

^

method OngoingStubbing.thenReturn(Single) is not applicable

(argument mismatch; Single cannot be converted to Single)

method OngoingStubbing.thenReturn(Single,Single...) is not applicable

(argument mismatch; Single cannot be converted to Single)

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

据我所知,这与

extends . . .>

作为签名的一部分,我成功地模仿了类似的顶点返回类似

Single

Maybe

不幸的是,在这种情况下,更改客户的签名是没有意义的。

我尝试将响应single指定为变量,并将其显式键入为

Single extends HttpResponse>

Single

莫基托的想法可能被某种类型的删除混淆了,但没有用。

有什么想法可能是导致这种情况的原因,以及如何解决它?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值