@CollectionSize.Require(absent = ZERO) @MapFeature.Require(SUPPORTS_PUT) public void testPutAllEmptyIterableOnPresentKey() { multimap().putAll(k0(), Collections.<V>emptyList()); expectUnchanged(); }
@MapFeature.Require(ALLOWS_NULL_KEYS) @CollectionSize.Require(absent = ZERO) public void testCreateWithNullKeySupported() { initMapWithNullKey(); expectContents(createArrayWithNullKey()); }
@MapFeature.Require(ALLOWS_NULL_VALUES) @CollectionSize.Require(absent = ZERO) public void testContains_nullContained() { initMapWithNullValue(); assertTrue("containsValue(null) should return true", getMap().containsValue(null)); }
@MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES) public void testContains_nullNotContainedAndUnsupported() { expectNullValueMissingWhenNullValuesUnsupported( "containsValue(null) should return false or throw"); }
@MapFeature.Require(SUPPORTS_PUT) public void testPutAllNonEmptyCollectionOnAbsentKey() { assertTrue(multimap().putAll(k3(), Lists.newArrayList(v3(), v4()))); assertGet(k3(), v3(), v4()); }
@CollectionSize.Require(SEVERAL) @MapFeature.Require(SUPPORTS_REMOVE) public void testKeysEntrySetRemove() { resetContainer( Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0())); assertTrue(multimap().keys().entrySet().remove(Multisets.immutableEntry(k0(), 2))); assertEquals(1, multimap().size()); assertTrue(multimap().containsEntry(k1(), v0())); } }
@MapFeature.Require(SUPPORTS_REMOVE) public void testKeysRemove() { int original = multimap().keys().remove(k0(), 1); assertEquals(Math.max(original - 1, 0), multimap().get(k0()).size()); }
@MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE}) @CollectionSize.Require(SEVERAL) public void testClearConcurrentWithEntrySetIteration() { try { Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator(); getMap().clear(); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@MapFeature.Require(SUPPORTS_REMOVE) public void testClear() { getMap().clear(); assertTrue("After clear(), a map should be empty.", getMap().isEmpty()); assertEquals(0, getMap().size()); assertFalse(getMap().entrySet().iterator().hasNext()); }
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) public void testPutNullKey() { int size = getNumElements(); multimap().put(null, v3()); assertGet(null, v3()); assertEquals(size + 1, multimap().size()); }
@MapFeature.Require(SUPPORTS_PUT) public void testPutEmpty() { int size = getNumElements(); assertGet(k3(), ImmutableList.<V>of()); assertTrue(multimap().put(k3(), v3())); assertGet(k3(), v3()); assertEquals(size + 1, multimap().size()); }
@MapFeature.Require(absent = SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_unsupportedWrongValue() { try { getMap().replace(k0(), v3(), v4()); } catch (UnsupportedOperationException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_wrongValueNullValueUnsupported() { try { assertFalse(getMap().replace(k0(), v3(), null)); } catch (NullPointerException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @MapFeature.Require(SUPPORTS_REMOVE) public void testRemoveAllPropagatesToGet() { Collection<V> getResult = multimap().get(k0()); multimap().removeAll(k0()); assertEmpty(getResult); expectMissing(e0()); }
@CollectionSize.Require(absent = ZERO) @MapFeature.Require(SUPPORTS_REMOVE) public void testRetainAllPropagatesToMultimap() { multimap().entries().retainAll(Collections.singleton(Helpers.mapEntry(k0(), v0()))); assertEquals(getSubjectGenerator().create(Helpers.mapEntry(k0(), v0())), multimap()); assertEquals(1, multimap().size()); assertTrue(multimap().containsEntry(k0(), v0())); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEY_QUERIES) public void testReplace_absentNullKeyUnsupported() { try { getMap().replace(null, v3()); } catch (NullPointerException tolerated) { // permitted not to throw because it would be a no-op } expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) public void testReplace_supportedAbsent() { assertNull(getMap().replace(k3(), v3())); expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplace_supportedPresentNoChange() { assertEquals(v0(), getMap().replace(k0(), v0())); expectUnchanged(); }
@MapFeature.Require(SUPPORTS_REMOVE) public void testAsMapRemoveImplementsSet() { List<K> keys = new ArrayList<K>(multimap().keySet()); for (K key : keys) { resetCollection(); assertTrue(multimap().asMap().remove(key) instanceof Set); } }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) @CollectionSize.Require(absent = ZERO) public void testPutIfAbsent_putWithNullValueUnsupported() { try { getMap().putIfAbsent(k0(), null); } catch (NullPointerException tolerated) { } expectUnchanged(); expectNullValueMissingWhenNullValuesUnsupported( "Should not contain null after unsupported putIfAbsent(present, null)"); } }