In fact, org.mockito.Matchers.eq uses the org.mockito.internal.matchers.Equality.areEqual(Object o1, Object o2) method to check if this matching element is equal to the actual value passed to the method. Interestingly, the implementation of this method was stolen from hamcrest, as indicated in the comment:
//stolen from hamcrest because I didn't want to have more dependency than Matcher class //... public static boolean areEqual(Object o1, Object o2) { if (o1 == o2 ) { return true; } else if (o1 == null || o2 == null) { return o1 == null && o2 == null; } else if (isArray(o1)) { return isArray(o2) && areArraysEqual(o1, o2); } else { return o1.equals(o2); } }
Place a breakpoint at the very beginning of this method to see what happens in your own code. Since you are passing an ArrayList the eq() argument , you may need to dig deeper into the areArraysEqual and areArrayLengthsEqual .
source share