Skip to content

Commit 2ab63a9

Browse files
committed
Enable tests
1 parent 63afa0e commit 2ab63a9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

hamcrest/src/test/java/org/hamcrest/collection/IsUnmodifiableCollectionTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import org.hamcrest.test.AbstractMatcherTest;
66
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.FieldSource;
79
import org.hamcrest.Matcher;
810

911
import java.util.*;
@@ -35,11 +37,29 @@ public class IsUnmodifiableCollectionTest extends AbstractMatcherTest {
3537
new String[]{null, SET_INT_INDEX_E_ELEMENT, ADD_INT_INDEX_E_ELEMENT, ADD_ALL_INT_INDEX_COLLECTION_EXTENDS_E_C, REMOVE_INT_INDEX, ADD_E_E, ADD_ALL_COLLECTION_EXTENDS_E_C, REMOVE_OBJECT_O, REMOVE_ALL_COLLECTION_C, RETAIN_ALL_COLLECTION_C, CLEAR}
3638
);
3739

40+
// TODO: Should I include Map.of().values()?
41+
private static final List<Collection<?>> JDK_KNOWN_UNMODIFIABLE_COLLECTIONS = List.of(Set.of(), List.of());
42+
private static final List<Collection<?>> JDK_KNOWN_MODIFIABLE_COLLECTIONS = List.of(
43+
new ArrayList(), new LinkedList(), new HashSet(), new LinkedHashSet(), new TreeSet(), new PriorityQueue(), new ArrayDeque());
44+
3845
@Override
3946
protected Matcher<?> createMatcher() {
4047
return isUnmodifiable();
4148
}
4249

50+
@ParameterizedTest
51+
@FieldSource("JDK_KNOWN_UNMODIFIABLE_COLLECTIONS")
52+
public void testMatchesKnownJdkUnmodifiableCollections(Collection<?> collection) {
53+
assertMatches("truly unmodifiable JDK Collection", isUnmodifiable(), collection);
54+
}
55+
56+
@ParameterizedTest
57+
@FieldSource("JDK_KNOWN_MODIFIABLE_COLLECTIONS")
58+
public void testMismatchesKnownJdkModifiableCollections(Collection<?> collection) {
59+
assertDoesNotMatch("modifiable JDK Collection", isUnmodifiable(), collection);
60+
}
61+
62+
4363
@Test
4464
public void testMatchesUnmodifiableList() {
4565
assertMatches("truly unmodifiable list", isUnmodifiable(), Collections.unmodifiableList(Collections.emptyList()));

0 commit comments

Comments
 (0)