How do you write unit test for the argument of a method call inside the method which returns void?
Have a look at the code snippet below:
As mentioned in the comment, the method countNumberCharacter simply counts the number of occurrences of character ch in the given string text. The count is then logged to the console via a utility method called log to console.
What if you want to write the unit test for the count?
Fortunately, Mockito comes with a Class called ArgumentCaptor. Argument Captor provides an opportunity to capture argument values for assertion.
We need to first add dependency of Mockito before using the Arguement Captor. Link to Mockito dependency.
Refer to the code snippet of junit test of the class shown above to see an example of Argument Captor at work.