i want to use Hamcrest’s hasItems
with an "actual" collection that is an ArrayList<? extends SomeInterface>
on
assertThat(ArrayList<? extends SomeInterface>, hasItems(InstanceOfSomeInterface))
the compiler says:
The method
assertThat(T, Matcher<T>)
in the typeAssert
is not applicable for the arguments(ArrayList<capture#9-of ? extends MyInterface>, Matcher<Iterable<MyInterface>>)
what is going wrong? What can i do about that (i really want to use Hamcrest here)?
ArrayList<SomeInterface> newList = new ArrayList<SomeInterface>();
newList.addAll(origList);
assertThat(newList, hasItems(InstanceOfSomeInterface));
It is unfortunate that Assert.assertThat was not coded using ? super or ? extends to allow for what you describe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With