New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockitoHamcrest#argThat does not allow "super" matchers #1817
Comments
Rather than making changes to Note that mockito/src/main/java/org/mockito/ArgumentMatchers.java Lines 1204 to 1207 in 68bc593
|
Thanks for the fast response @TimvdLippe I am very sorry to hear that hamcrest matcher support may get deprecated :-( With the hamcrest matcher support in mockito it was very easy to share matcher implantations over multiple usecases. For example I use the same matcher in:
For me dropping the support would mean to rewrite (and maintain) a tone of matchers as ArgumentMatcher. Please do not drop Hamcrest Matcher support. Best Regards, |
We are keeping this deprecated, but won't delete it for now. |
IMHO to really follow the hamcrest matchers design philosophy the argThat interface should look like this:
public static <T> T argThat(Matcher<? super T> matcher)
, but unfortunately it ismockito/src/main/java/org/mockito/hamcrest/MockitoHamcrest.java
Line 60 in 68bc593
this change would allow a statement like the following:
verify(mock).aMethod(argThat(nullValue()))
I see that the default value is derived from the concrete matcher type, which of course would not work anymore. To circumvent this problem, it would be possible to provide a overload for primitives types.
Or provide a new argThat method, for example argThatSuper which always returns null, but of course would not work for primitive types. Than the existing argThat would keep its behavior.
The text was updated successfully, but these errors were encountered: