As David Wallace has said, you'll need to use Mockito.spy(T object)
.
So with a simple method:
public void runArgumentCaptor() {
logError("This is an error");
}
The test can look like this:
@Spy @InjectMocks private SomeClassName testObj;
@Test(groups = { "unit" })
public void runArgumentCaptorTest() throws Exception {
testObj.runArgumentCaptor();
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
Mockito.verify(testObj).logError(argumentCaptor.capture());
Assert.assertEquals(argumentCaptor.getValue(), "This is an error");
}
[EDIT]
Added the declaration of testObj
. Note the additional @Spy
. Also updated the test method.