when(validator.isValid(Sets.newHashSet("valid"))).thenReturn(true);
When validator.isValid(set)
is invoked it returns false. It is because the validator implementation creates a new set that is different that the passed one (reference is different) - the items in both sets are same.
I need to return true if sets contains same items regardless of sets instances.
Something similar to org.mockito.Matchers
:
public static <T> Set<T> anySetOf(Class<T> clazz) {
return (Set) reportMatcher(Any.ANY).returnSet();
}
except that I would pass instances not Class<T>.class
.
And same for verify
:
verify(validator, times(1)).isValid(Sets.newHashSet("valid"));
Is there such a matcher?