使用 ArgumentCaptor 驗證呼叫引數

ArgumentCaptor 將接收已傳遞給方法的實際呼叫引數。

 placeholderCopyArgumentCaptor<Foo> captor = ArgumentCaptor.forClass(Foo.class);
verify(mockObj).doSomethind(captor.capture());
Foo invocationArg = captor.getValue();
//do any assertions on invocationArg

對於多次呼叫 mocked 方法來接收所有呼叫引數的情況

 placeholderCopyList<Foo> invocationArgs = captor.getAllValues();

相同的方法用於捕獲 varargs。

還有可能使用 @Captor 註釋建立 ArgumentCaptor

 placeholderCopy@Captor
private ArgumentCaptor<Foo> captor;