Skip to content

Commit fbcac75

Browse files
author
smgfreeman
committed
confirmed that Issue 24 (IsCollectionContaining doesn't support subtypes) works
1 parent 1b571e7 commit fbcac75

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContainingTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import static org.hamcrest.core.IsEqual.equalTo;
77

88
import java.util.ArrayList;
9+
import java.util.HashSet;
10+
import java.util.Set;
911

1012
import org.hamcrest.AbstractMatcherTest;
1113
import org.hamcrest.Matcher;
14+
import org.hamcrest.MatcherAssert;
1215

1316
public class IsCollectionContainingTest extends AbstractMatcherTest {
1417
@Override
@@ -41,6 +44,13 @@ public void testDoesNotMatchNull() {
4144
public void testHasAReadableDescription() {
4245
assertDescription("a collection containing \"a\"", hasItem(equalTo("a")));
4346
}
47+
48+
public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24
49+
{
50+
final Set<Number> s = new HashSet<Number>();
51+
s.add(Integer.valueOf(2));
52+
MatcherAssert.assertThat(s, hasItem(Integer.valueOf(2)));
53+
}
4454

4555
@SuppressWarnings("unchecked")
4656
public void testMatchesAllItemsInCollection() {
@@ -70,3 +80,4 @@ public void testMatchesAllItemsInCollection() {
7080
asList("e", "c", "b", "d")); // 'a' missing
7181
}
7282
}
83+

0 commit comments

Comments
 (0)