问题描述
我对 Mockito 很陌生,正在尝试为下面的 post 方法编写测试用例
public Mono(Resonse) getReceivers(Request request)
return webClient.post().uri.url("/receivers").body(Mono.just(request),Request.class)
.retrieve().bodyToMono(response.clss)
实际上我的响应类是一个包装类,它返回具有 Id、name 等的 List 列表
我的请求类是简单的类,有 2 个字段键和方法。
我正在尝试这样做,但它给了我错误:
Request request = new Request();
request.setKey(1111L);
request.setMethod("ONLINE");
when(webClientMock.post()).thenReturn(requestBodyUriSpecmock);
when(requestBodyUriSpecmock.uri(anyString())).thenReturn(requestBodySpecmock);
when(requestBodySpecmock.header(any(),any())).thenReturn(requestBodySpecmock);
when(requestBodySpecmock.body(any())).thenReturn(requestHeadeRSSpecmock);
when(requestHeadeRSSpecmock.retrieve()).thenReturn(responseSpecmock);
when(responseSpecmock.bodyToMono(
ArgumentMatchers.<Class<Post>>notNull())).thenReturn(Mono.just(request));
Mono<Response> response = proxy.getRecievers(request);
Assertions.assertEquals("ONLINE",response.block().getRecievers().getmethod());
我的测试有意义吗? 请帮忙
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)