Skip to content
Advertisement

Invalid use of argument matchers! 2 matchers expected, 1 recorded

I am writing a test to validate creations of trolleys. So,it is just a service method which basically creates number of trolleys in the database. I am mocking the repository using mockito.

So, What i am doing is I am mocking and save and getAll functionality of Repository.

Here is what my code looks like:-

JavaScript

So initially i am just taking an empty array list and mocking the save method to add to the list. Because service method calls the save method which takes a trolley and save it to db for each trolley it creates and it returns Page Of Trolley which calls the findAllByStoreHouseCode which takes storehousecode and a PageRequest.

Error occurs on the line where i am using the any ArgumentMatcher. I am new to testing could any one please tell me where i am wrong or this approach is wrong and i should implement test in some other way.

Here is the error:-

JavaScript

Advertisement

Answer

Try changing your Mockito setup to below

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement