user123
user123

Reputation: 281

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?

Upvotes: 19

Views: 16579

Answers (1)

Rachel Gallen
Rachel Gallen

Reputation: 28553

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());

Upvotes: 25

Related Questions