/** * The supplied multimap will be mutated and an unmodifiable instance used * in its stead. If the multimap does not support null keys or values, * alternatives may be specified for tests involving nulls. */ private static void checkUnmodifiableMultimap( Multimap<String, Integer> multimap, boolean permitsDuplicates, @Nullable String nullKey, @Nullable Integer nullValue) { Multimap<String, Integer> unmodifiable = prepareUnmodifiableTests(multimap, permitsDuplicates, nullKey, nullValue); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable( unmodifiable, "test", 123); assertUnmodifiableIterableInTandem( unmodifiable.keys(), multimap.keys()); assertUnmodifiableIterableInTandem( unmodifiable.keySet(), multimap.keySet()); assertUnmodifiableIterableInTandem( unmodifiable.entries(), multimap.entries()); assertUnmodifiableIterableInTandem( unmodifiable.asMap().entrySet(), multimap.asMap().entrySet()); assertEquals(multimap.toString(), unmodifiable.toString()); assertEquals(multimap.hashCode(), unmodifiable.hashCode()); assertEquals(multimap, unmodifiable); assertThat(unmodifiable.asMap().get("bar")).containsExactly(5, -1); assertNull(unmodifiable.asMap().get("missing")); assertFalse(unmodifiable.entries() instanceof Serializable); }
private static <T> void assertUnmodifiableIterableInTandem( Iterable<T> unmodifiable, Iterable<T> modifiable) { UnmodifiableCollectionTests.assertIteratorIsUnmodifiable( unmodifiable.iterator()); UnmodifiableCollectionTests.assertIteratorsInOrder( unmodifiable.iterator(), modifiable.iterator()); }
/** * The supplied multimap will be mutated and an unmodifiable instance used in its stead. If the * multimap does not support null keys or values, alternatives may be specified for tests * involving nulls. */ private static void checkUnmodifiableMultimap( Multimap<String, Integer> multimap, boolean permitsDuplicates, @NullableDecl String nullKey, @NullableDecl Integer nullValue) { Multimap<String, Integer> unmodifiable = prepareUnmodifiableTests(multimap, permitsDuplicates, nullKey, nullValue); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable(unmodifiable, "test", 123); assertUnmodifiableIterableInTandem(unmodifiable.keys(), multimap.keys()); assertUnmodifiableIterableInTandem(unmodifiable.keySet(), multimap.keySet()); assertUnmodifiableIterableInTandem(unmodifiable.entries(), multimap.entries()); assertUnmodifiableIterableInTandem( unmodifiable.asMap().entrySet(), multimap.asMap().entrySet()); assertEquals(multimap.toString(), unmodifiable.toString()); assertEquals(multimap.hashCode(), unmodifiable.hashCode()); assertEquals(multimap, unmodifiable); assertThat(unmodifiable.asMap().get("bar")).containsExactly(5, -1); assertNull(unmodifiable.asMap().get("missing")); assertFalse(unmodifiable.entries() instanceof Serializable); }
public void testMultisetWrites() { Multiset<String> multiset = ImmutableMultiset.of("a", "b", "a"); UnmodifiableCollectionTests.assertMultisetIsUnmodifiable(multiset, "test"); }
public void testEmptyMultimapWrites() { Multimap<String, Integer> multimap = ImmutableListMultimap.of(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable( multimap, "foo", 1); }
public void testMultimapWrites() { Multimap<String, Integer> multimap = createMultimap(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable( multimap, "bar", 2); }
public void testEmptyMultimapWrites() { Multimap<String, Integer> multimap = ImmutableSetMultimap.of(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable( multimap, "foo", 1); }
public void testMultisetWrites() { Multiset<String> multiset = ImmutableSortedMultiset.of("a", "b", "a"); UnmodifiableCollectionTests.assertMultisetIsUnmodifiable(multiset, "test"); }
public void testEmptyMultimapWrites() { Multimap<String, Integer> multimap = ImmutableListMultimap.of(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable(multimap, "foo", 1); }
public void testMultimapWrites() { Multimap<String, Integer> multimap = createMultimap(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable(multimap, "bar", 2); }
public void testEmptyMultimapWrites() { Multimap<String, Integer> multimap = ImmutableSetMultimap.of(); UnmodifiableCollectionTests.assertMultimapIsUnmodifiable(multimap, "foo", 1); }
private static <T> void assertUnmodifiableIterableInTandem( Iterable<T> unmodifiable, Iterable<T> modifiable) { UnmodifiableCollectionTests.assertIteratorIsUnmodifiable(unmodifiable.iterator()); UnmodifiableCollectionTests.assertIteratorsInOrder( unmodifiable.iterator(), modifiable.iterator()); }