简体   繁体   中英

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. see here

Example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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