I have methods like these:
public <T> method(String s, Class<T> t) {...}
That I need to check that null
is passed to the second argument when using matchers for the other parameters, I have been doing this :
@SuppressWarnings("unchecked")
verify(client).method(eq("String"), any(Class.class));
But is there a better way (without suppress warnings) ? T
represents the return type of some other method, which is sometimes void
and in these cases null
is passed in.
Mockito has an isNull
matcher, where you can pass in the name of the class. So if you need to use it with other matchers, the correct thing to do is
verify(client).method(eq("String"),isNull(Class<?>.class));
This is now deprecated, see the answer below for the new method - https://stackoverflow.com/a/41250852/1348