5. Capturing arguments passed to a mock:
String expected = "test string";Note that this capture code can come after the call to the production method.
toTest.hitTakeArgumentReturnVoid(expected);
ArgumentCaptorstringCaptor = ArgumentCaptor.forClass(String.class);
Mockito.verify(mock).takeArgumentReturnVoid(stringCaptor.capture());
Assert.assertEquals(expected, stringCaptor.getValue());
6. Verifying that a method is never called:
Mockito.verify(mock, Mockito.never()).takeArguments(Mockito.anyString(), Mockito.anyInt());
Or, equivalently:
Mockito.verify(mock, Mockito.times(0)).takeArguments(Mockito.anyString(), Mockito.anyInt());
But I don't like this as the set of methods never called is infinite.
No comments:
Post a Comment