If you look closely, nullValue(Class<T>)
simply creates a IsNull<T>
matcher.
So, if you are calling:
public static <T> Matcher<T> nullValue(Class<T> type) {
return new IsNull<T>();
}
In the end (as the generics are giving a hard time because you can't figure out the runtime class of a potentially null
object), you could just call the constructor directly:
new IsNull<Iterable<? extends Foo>>();
So a solution would be to just use it, without the nullValue()
utility method:
/**
* Matches all Foo objects in an order agnostic manner.
* @param expected The collection of Foo objects to be matched.
* @return A matcher that will match a collection of Foos
*/
@SuppressWarnings("unchecked")
public static Matcher<Iterable<? extends Foo>> matchesAllfoos(Collection<Foo> expected)
{
if (expected == null)
{
return new IsNull<Iterable<? extends Foo>>();
}
// The cast is here to provide a hint to Java as to which overloaded method to choose.
// See http://stackoverflow.com/questions/18614621/conflicting-overloads-for-hamcrest-matcher
return containsInAnyOrder((Collection)Collections2.transform(expected, FOO_TO_MATCHER));
}