使用Mockito验证在方法之后没有调用任何东西

使用Mockito验证在方法之后没有调用任何东西,第1张

使用Mockito验证在方法之后没有调用任何东西

我认为这需要更多的定制工作。

verify(row, new LastCall()).saveToDatabase();

然后

public class LastCall implements VerificationMode {    public void verify(VerificationData data) {        List<Invocation> invocations = data.getAllInvocations();        InvocationMatcher matcher = data.getWanted();        Invocation invocation = invocations.get(invocations.size() - 1);        if (!matcher.matches(invocation)) throw new MockitoException("...");    }}

上一个答案:

你是对的。verifyNoMoreInteractions是您所需要的。

verify(row).setSomething(value);verify(row).setSomethingElse(anotherValue);verify(row).editABunchMoreStuff();verify(row).saveToDatabase();verifyNoMoreInteractions(row);


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5500807.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存