/* Matches any class that has an <code>isEmpty()</code> method * that returns a <code>boolean</code> */ public class IsEmpty<T> extends TypeSafeMatcher<T> { @Factory public static <T> Matcher<T> empty() { return new IsEmpty<T>(); } @Override protected boolean matchesSafely(@Nonnull final T item) { try { return (boolean) item.getClass().getMethod("isEmpty", (Class<?>[]) null).invoke(item); } catch (final NoSuchMethodException e) { return false; } catch (final InvocationTargetException | IllegalAccessException e) { throw new RuntimeException(e); } } @Override public void describeTo(@Nonnull final Description description) { description.appendText("is empty"); } }