Class UnmodifiableCollectionTests
java.lang.Object
com.google.common.collect.testing.google.UnmodifiableCollectionTests
A series of tests that support asserting that collections cannot be modified, either through
direct or indirect means.
- Author:
- Robert Konigsberg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends @Nullable Object>
voidassertCollectionIsUnmodifiable
(Collection<E> collection, E sampleElement) Verifies that a collection is immutable.static void
assertIteratorIsUnmodifiable
(Iterator<?> iterator) Verifies that an Iterator is unmodifiable.static void
assertIteratorsInOrder
(Iterator<?> expectedIterator, Iterator<?> actualIterator) Asserts that two iterators contain elements in tandem.static void
assertMapEntryIsUnmodifiable
(Map.Entry<?, ?> entry) assertMultimapIsUnmodifiable
(com.google.common.collect.Multimap<K, V> multimap, K sampleKey, V sampleValue) Verifies that a multimap is immutable.static <E extends @Nullable Object>
voidassertMultisetIsUnmodifiable
(com.google.common.collect.Multiset<E> multiset, E sampleElement) Verifies that a multiset is immutable.static <E extends @Nullable Object>
voidassertSetIsUnmodifiable
(Set<E> set, E sampleElement) Verifies that a set is immutable.
-
Constructor Details
-
UnmodifiableCollectionTests
public UnmodifiableCollectionTests()
-
-
Method Details
-
assertMapEntryIsUnmodifiable
-
assertIteratorIsUnmodifiable
Verifies that an Iterator is unmodifiable.This test only works with iterators that iterate over a finite set.
-
assertIteratorsInOrder
-
assertCollectionIsUnmodifiable
public static <E extends @Nullable Object> void assertCollectionIsUnmodifiable(Collection<E> collection, E sampleElement) Verifies that a collection is immutable.A collection is considered immutable if:
- All its mutation methods result in UnsupportedOperationException, and do not change the underlying contents.
- All methods that return objects that can indirectly mutate the collection throw UnsupportedOperationException when those mutators are called.
- Parameters:
collection
- the presumed-immutable collectionsampleElement
- an element of the same type as that contained bycollection
.collection
may or may not havesampleElement
as a member.
-
assertSetIsUnmodifiable
public static <E extends @Nullable Object> void assertSetIsUnmodifiable(Set<E> set, E sampleElement) Verifies that a set is immutable.A set is considered immutable if:
- All its mutation methods result in UnsupportedOperationException, and do not change the underlying contents.
- All methods that return objects that can indirectly mutate the set throw UnsupportedOperationException when those mutators are called.
- Parameters:
set
- the presumed-immutable setsampleElement
- an element of the same type as that contained byset
.set
may or may not havesampleElement
as a member.
-
assertMultisetIsUnmodifiable
public static <E extends @Nullable Object> void assertMultisetIsUnmodifiable(com.google.common.collect.Multiset<E> multiset, E sampleElement) Verifies that a multiset is immutable.A multiset is considered immutable if:
- All its mutation methods result in UnsupportedOperationException, and do not change the underlying contents.
- All methods that return objects that can indirectly mutate the multiset throw UnsupportedOperationException when those mutators are called.
- Parameters:
multiset
- the presumed-immutable multisetsampleElement
- an element of the same type as that contained bymultiset
.multiset
may or may not havesampleElement
as a member.
-
assertMultimapIsUnmodifiable
public static <K extends @Nullable Object, V extends @Nullable Object> void assertMultimapIsUnmodifiable(com.google.common.collect.Multimap<K, V> multimap, K sampleKey, V sampleValue) Verifies that a multimap is immutable.A multimap is considered immutable if:
- All its mutation methods result in UnsupportedOperationException, and do not change the underlying contents.
- All methods that return objects that can indirectly mutate the multimap throw UnsupportedOperationException when those mutators
- Parameters:
multimap
- the presumed-immutable multimapsampleKey
- a key of the same type as that contained bymultimap
.multimap
may or may not havesampleKey
as a key.sampleValue
- a key of the same type as that contained bymultimap
.multimap
may or may not havesampleValue
as a key.
-