简体   繁体   English

论证俘虏mockito

[英]Argument captor mockito

I have been doing a bit of reading around argument captor and the more I read about it, the more I get lost. 我一直在阅读有关参数捕获者的内容,我读的越多,我就越迷失。 Can someone take the pain of explaining it with an example? 有人可以用一个例子解释它的痛苦吗?

According to docs, this is deprecated. 根据文档,这已被弃用。 You should use factory method forClass(Class) to create captors instead to avoid NullPointerExceptions. 您应该使用工厂方法forClass(Class)来创建绑定器,以避免NullPointerExceptions。 see here 看到这里

Example: 例:

  ArgumentCaptor<Person> argument = ArgumentCaptor.forClass(Person.class);
  verify(mock).doSomething(argument.capture());
  assertEquals("John", argument.getValue().getName());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM