JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Collection matchers cannot take a collection of elements

Open phoenix384 opened this issue 6 years ago • 2 comments

The matchers IsIterableContaining, IsIterableContainingInRelativeOrder, IsIterableContainingInOrder and IsIterableContainingInAnyOrder all have methods accepting

  1. further matchers as a varargs parameter
  2. a collection of matchers
  3. expected elements as a varargs parameter

They are all missing a method taking the expected elements as a Collection<E> or Iterable<E>. If you already have a list of expected elements, you always have to convert it into an array in order to use these matchers.

Is there a reason why these methods are missing? Otherwise I could create a pull request to add them.

phoenix384 avatar Jul 01 '19 10:07 phoenix384

I haven't checked, but I would guess that since the generic types are stripped from the compiled code, then the Java runtime would not be able to differentiate a parameter of Collection<T> from Collection<Matcher<T>>.

tumbarumba avatar Aug 25 '19 23:08 tumbarumba

The API is a bit of a mess and one of the things that contributes to that is Java's brittle type system. Things that involve two levels of generic <ListOf<Thing>> cost me a year of my life.

sf105 avatar Aug 26 '19 14:08 sf105