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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> voidassertCollectionIsUnmodifiable(Collection<E> collection, E sampleElement) Verifies that a collection is immutable.private static <E> voidassertCollectionsAreEquivalent(Collection<E> expected, Collection<E> actual) static voidassertIteratorIsUnmodifiable(Iterator<?> iterator) Verifies that an Iterator is unmodifiable.static voidassertIteratorsInOrder(Iterator<?> expectedIterator, Iterator<?> actualIterator) Asserts that two iterators contain elements in tandem.static voidassertMapEntryIsUnmodifiable(Map.Entry<?, ?> entry) static <K,V> void assertMultimapIsUnmodifiable(Multimap<K, V> multimap, K sampleKey, V sampleValue) Verifies that a multimap is immutable.private static <K,V> void assertMultimapRemainsUnmodified(Multimap<K, V> expected, List<Map.Entry<K, V>> actual) static <E> voidassertMultisetIsUnmodifiable(Multiset<E> multiset, E sampleElement) Verifies that a multiset is immutable.static <E> 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
Asserts that two iterators contain elements in tandem.This test only works with iterators that iterate over a finite set.
-
assertCollectionIsUnmodifiable
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.collectionmay or may not havesampleElementas a member.
-
assertSetIsUnmodifiable
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.setmay or may not havesampleElementas a member.
-
assertMultisetIsUnmodifiable
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.multisetmay or may not havesampleElementas a member.
-
assertMultimapIsUnmodifiable
public static <K,V> void assertMultimapIsUnmodifiable(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.multimapmay or may not havesampleKeyas a key.sampleValue- a key of the same type as that contained bymultimap.multimapmay or may not havesampleValueas a key.
-
assertCollectionsAreEquivalent
private static <E> void assertCollectionsAreEquivalent(Collection<E> expected, Collection<E> actual) -
assertMultimapRemainsUnmodified
-