11package org .hamcrest .collection ;
22
33import static java .util .Arrays .asList ;
4+ import static org .hamcrest .MatcherAssert .assertThat ;
45import static org .hamcrest .core .IsCollectionContaining .hasItem ;
56import static org .hamcrest .core .IsCollectionContaining .hasItems ;
67import static org .hamcrest .core .IsEqual .equalTo ;
1112
1213import org .hamcrest .AbstractMatcherTest ;
1314import org .hamcrest .Matcher ;
14- import org .hamcrest .MatcherAssert ;
15+ import org .hamcrest .core .IsCollectionContaining ;
16+ import org .hamcrest .core .IsEqual ;
1517
1618public class IsCollectionContainingTest extends AbstractMatcherTest {
1719 @ Override
@@ -20,19 +22,19 @@ protected Matcher<?> createMatcher() {
2022 }
2123
2224 public void testMatchesACollectionThatContainsAnElementMatchingTheGivenMatcher () {
23- Matcher <Iterable <String >> itemMatcher = hasItem (equalTo ("a" ));
25+ Matcher <Iterable <? super String >> itemMatcher = hasItem (equalTo ("a" ));
2426
2527 assertMatches ("should match list that contains 'a'" ,
2628 itemMatcher , asList ("a" , "b" , "c" ));
2729 }
2830
2931 public void testDoesNotMatchCollectionThatDoesntContainAnElementMatchingTheGivenMatcher () {
30- final Matcher <Iterable <String >> matcher1 = hasItem (equalTo ("a" ));
32+ final Matcher <Iterable <? super String >> matcher1 = hasItem (equalTo ("a" ));
3133 assertDoesNotMatch ("should not match list that doesn't contain 'a'" ,
3234 matcher1 , asList ("b" , "c" ));
3335
3436
35- final Matcher <Iterable <String >> matcher2 = hasItem (equalTo ("a" ));
37+ final Matcher <Iterable <? super String >> matcher2 = hasItem (equalTo ("a" ));
3638 assertDoesNotMatch ("should not match the empty list" ,
3739 matcher2 , new ArrayList <String >());
3840 }
@@ -49,7 +51,8 @@ public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24
4951 {
5052 final Set <Number > s = new HashSet <Number >();
5153 s .add (Integer .valueOf (2 ));
52- MatcherAssert .assertThat (s , hasItem (Integer .valueOf (2 )));
54+ assertThat (s , new IsCollectionContaining <Number >(new IsEqual <Object >(Integer .valueOf (2 ))));
55+ assertThat (s , IsCollectionContaining .hasItem (Integer .valueOf (2 )));
5356 }
5457
5558 @ SuppressWarnings ("unchecked" )
0 commit comments