|
4 | 4 |
|
5 | 5 | import org.hamcrest.test.AbstractMatcherTest; |
6 | 6 | import org.junit.jupiter.api.Test; |
| 7 | +import org.junit.jupiter.params.ParameterizedTest; |
| 8 | +import org.junit.jupiter.params.provider.FieldSource; |
7 | 9 | import org.hamcrest.Matcher; |
8 | 10 |
|
9 | 11 | import java.util.*; |
@@ -35,11 +37,29 @@ public class IsUnmodifiableCollectionTest extends AbstractMatcherTest { |
35 | 37 | 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} |
36 | 38 | ); |
37 | 39 |
|
| 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 | + |
38 | 45 | @Override |
39 | 46 | protected Matcher<?> createMatcher() { |
40 | 47 | return isUnmodifiable(); |
41 | 48 | } |
42 | 49 |
|
| 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 | + |
43 | 63 | @Test |
44 | 64 | public void testMatchesUnmodifiableList() { |
45 | 65 | assertMatches("truly unmodifiable list", isUnmodifiable(), Collections.unmodifiableList(Collections.emptyList())); |
|
0 commit comments