我有以下模拟:
when(manager.list(eq(userId), eq(0), isNull())).thenReturn(completedFuture(user));
// call some method
verify(configurationsManager).list(any(), any(), isNull());
当我运行这个时,我得到一个
org.mockito.exceptions.misusing.UnfinishedVerificationException:
Missing method call for verify(mock) here:
它引用 verify(configurationsManager).list(any(), any(), isNull());
行。我做错了什么?
list
方法是:
public CompletionStage<User> list(UserId, int, Token)
其中 UserId
和 Token
是自定义类。
最佳答案
我认为您的问题可能是在匹配 list()
方法的第二个 int
类型变量时使用 any()
方法。根据我的经验,any()
方法往往不适用于原始类型。因此,我会使用 anyInteger()
来代替。因此,您的新行将是:
verify(configurationsManager).list(any(), anyInteger(), isNull());
关于使用 isNull 时出现 Java UnfinishedVerificationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60010741/