试图用INT参数模拟方法,但Mockito失败
我想模拟以下方法的响应:
public JobResult getJobResult(String jobId, int pageSize, String cursor)
以下方法:
when(analyticsApi.getJobResult(any(), any(), any())).thenReturn(jobResult);
但是摩根托失败了以下错误:
java.lang.nullpointerexception:无法调用 “ java.lang.integer.intvalue()”,因为 “ org.mockito.argumentMatchers.any()”为null
I want to simulate the response of the following method:
public JobResult getJobResult(String jobId, int pageSize, String cursor)
The following way:
when(analyticsApi.getJobResult(any(), any(), any())).thenReturn(jobResult);
But Mockito fails with the following error:
java.lang.NullPointerException: Cannot invoke
"java.lang.Integer.intValue()" because the return value of
"org.mockito.ArgumentMatchers.any()" is null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,您不能将任何()放在int参数上,因此您必须以以下方式模拟它:
Turns out you cannot put any() on int parameters, so you have to mock it the following way: