Capture parameters with Mockito ArgumentCaptor
While creating test methods for a class, you might want to access some arguments passed to a specific method. Luckily, you can capture parameters with Mockito ArgumentCaptor. It is especially useful when you can’t access the argument from the outside of the method.
Let’s check it out on a basic example. Let’s say we have a class called Product
and we create stock codes for these objects before saving them to the database. So we’ve created a method called generateProductCodeAndSave()
which generates the code then passes the product to another method in order to insert it to the database.