title: Hamcrest Matchers.contains matcher not working (?)
body: <p>I am trying to test if a collection has an item which toString() method returns a particular String. I tried do it using excellent Hamcrest matching classes, by combining contains with <code>Matchers.hasToString</code>, but somehow, its <code>Matchers.contains</code> is not being able to match an item even though it is present in the collection.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>class Item {
  
      private String name;
  
      public Item(String name){
          this.name = name;
      }
  
      public String toString(){
          return name;
      }
  }
  
  // here's a sample collection, with the desired item added in the end
  Collection&lt;Item&gt; items = new LinkedList&lt;Item&gt;(){{ 
      add(new Item("a")); 
      add(new Item("b"));
      add(new Item("c")); 
  }};
  
  Assert.assertThat(items, Matchers.contains(Matchers.hasToString("c")));
  </code></pre>
  
  <p>The above assertion is not successful. Here's the message:</p>
  
  <pre><code>java.lang.AssertionError: 
  Expected: iterable containing [with toString() "c"]
       but: item 0: toString() was "a"
      at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
      at org.junit.Assert.assertThat(Assert.java:865)
      at org.junit.Assert.assertThat(Assert.java:832)
  </code></pre>
  
  <p>It looks like the Matchers.contains matcher tries to iterate over the list, but the Matchers.hasToString matcher fails in the first item and invalidates the rest of the iteration. Hamcrest javadoc for Matchers.contains says:</p>
  
  <p>"Creates a matcher for Iterables that matches when a single pass over the examined Iterable yields a single item that satisfies the specified matcher. For a positive match, the examined iterable must only yield one item"</p>
  
  <p>Am I doing something wrong?</p>