Reputation: 2437
I am testing a class with mockito. It contains these methods:
add(Sortable s)
List<Sortable> get()
The class does several things to the objects internally, and it is dependant on sorting the Sortable objects.
The problem is that I am mocking Sortable, which makes compareTo() always return 0. Is there a way to make a Sorting mock that has the original Sortable compareTo() implementation? Or are there other ways to solve this?
Upvotes: 1
Views: 2902
Reputation: 466
Use statement like this before mocked object compareTo() method calling:
when(mockedObject.compareTo(any(Sortable.class))).thenCallRealMethod();
Upvotes: 9