Export to GitHub

hamcrest - issue #210

Matchers.contains does not always work for lists


Posted on Aug 5, 2014 by Quick Rhino

I am linking with hamcrest-all-1.3.jar.

The example given for

org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(org.hamcrest.Matcher<? super E> itemMatcher)

is

assertThat(Arrays.asList("foo"), contains(equalTo("foo")));

This works, but

assertThat(Arrays.asList("bar", "foo"), contains(equalTo("foo")));

fails! It only seems to try matching the first item in the list.

Comment #1

Posted on Mar 4, 2015 by Quick Horse

Isn't that the definition of contains()? If you didn't want the order to matter, isn't that containsInAnyOrder() instead?

Status: New