I have been scratching my head a lot over something which just happened with Mockito.
I have this class, called ExamineFilter, which up to now has not been parameterised. 150+ tests to do with this class and others all passing fine. Lots of mocking.
I then changed ExamineFilter from
public class ExamineFilter extends FilteringTokenFilter implements GettableSet<UniqueSequence> {
to
public class ExamineFilter<V extends UniqueSequenceInterface> extends FilteringTokenFilter implements GettableSet<V> {
Now, when I have a spy of ExamineFilter, and go
spyExamineFilter.add( ... )
... this method add is not called but the code carries on. Whereas it was called before.
The add method here is in fact from Set, because GettableSet extends Set, and the signature of Set.add is
public boolean add( V element ){ ...
... each time this method is called on the spy it is returning false... which seems to be what a mock would do if such a boolean-returning method was being mocked.
I've also checked that this is indeed what is going on by finding out what happens if instead of using a spy of ExamineFilter<...> I use a real ExamineFilter<...>: and, indeed, add is called as normal.
Is there a known and documented explanation for this Mockito behaviour? Obviously I'm now trying to think of workarounds to rewrite the handful of tests which have now gone red as a result...
Addendum
By the way, for anyone interested, I tried both "flavours" of "callRealMethod":
doCallRealMethod().when( spyExamineFilter ).add( any() ); // results in immediate call (i.e. at this line!) with null argument to add()
when( spyExamineFilter.add( any())).thenCallRealMethod(); // results in mock "add" call when add() invoked
when( spyExamineFilter.add( any( UniqueSequence.class ))).thenCallRealMethod(); // results in mock "add" call when add() invoked
when( spyExamineFilter.add( notNull() )).thenCallRealMethod(); // results in mock "add" call when add() invoked
... if any passing Mockito high priests come this way: does any of the above suggest anomalous behaviour which might actually warrant raising an issue with the Mockito team?