Reputation: 3737
I am trying to use mockito's ArgumentCaptor
class to capture some parameter and then do some verifications on it. But it's throwing an exception.
This is what is printed as the error message.
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 0 matchers expected, 1 recorded:
Below is the code which is throwing the exception.
//Arrange
int amount = 100;
DonationTransaction transaction = getPendingTransaction(player, amount);
when(mockDonationTransactionDAO.getPendingTransactions(player)).thenReturn(Arrays.asList(transaction));
ArgumentCaptor<DonationAttribution> argumentCaptor = ArgumentCaptor.forClass(DonationAttribution.class);
//Act
donationService.applyPendingDonations(player, playerDTO);
//Assert
verify(mockDonationAttributionDAO).save(argumentCaptor.capture()); //Exception here
...
I am using Junit5 and mockito version 2.7.22.
Not sure if I am missing something obvious here.
My DonationAttributionDao extends an abstract DAO if that helps with anything and the save method is defined in the abstract class which takes as parameter the base class of the Argument I am trying to capture.
Upvotes: 1
Views: 2166
Reputation: 1991
The save() method is static or final. Thus, you cannot mock it. You can try to use PowerMock instead (see Mockito - 0 Matchers Expected, 1 Recorded (InvalidUseOfMatchersException)).
Upvotes: 3