001/*
002 * Copyright (C) 2012 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect.testing.google;
018
019import static com.google.common.collect.testing.Helpers.assertContentsAnyOrder;
020import static com.google.common.collect.testing.Helpers.assertEmpty;
021import static com.google.common.collect.testing.Helpers.mapEntry;
022import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
023import static com.google.common.collect.testing.features.CollectionSize.ZERO;
024import static com.google.common.collect.testing.features.MapFeature.ALLOWS_ANY_NULL_QUERIES;
025import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
026import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
027import static com.google.common.collect.testing.google.GoogleHelpers.assertEmpty;
028
029import com.google.common.annotations.GwtCompatible;
030import com.google.common.collect.Multimap;
031import com.google.common.collect.testing.features.CollectionSize;
032import com.google.common.collect.testing.features.MapFeature;
033import java.util.Collection;
034
035/**
036 * Tests for {@link Multimap#removeAll(Object)}.
037 *
038 * @author Louis Wasserman
039 */
040@GwtCompatible
041public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
042  @MapFeature.Require(SUPPORTS_REMOVE)
043  public void testRemoveAllAbsentKey() {
044    assertEmpty(multimap().removeAll(k3()));
045    expectUnchanged();
046  }
047
048  @CollectionSize.Require(absent = ZERO)
049  @MapFeature.Require(SUPPORTS_REMOVE)
050  public void testRemoveAllPresentKey() {
051    assertContentsAnyOrder(multimap().removeAll(k0()), v0());
052    expectMissing(e0());
053  }
054
055  @CollectionSize.Require(absent = ZERO)
056  @MapFeature.Require(SUPPORTS_REMOVE)
057  public void testRemoveAllPropagatesToGet() {
058    Collection<V> getResult = multimap().get(k0());
059
060    multimap().removeAll(k0());
061
062    assertEmpty(getResult);
063    expectMissing(e0());
064  }
065
066  @CollectionSize.Require(SEVERAL)
067  @MapFeature.Require(SUPPORTS_REMOVE)
068  public void testRemoveAllMultipleValues() {
069    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v2()));
070
071    assertContentsAnyOrder(multimap().removeAll(k0()), v0(), v1(), v2());
072    assertEmpty(multimap());
073  }
074
075  @CollectionSize.Require(absent = ZERO)
076  @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS})
077  public void testRemoveAllNullKeyPresent() {
078    initMultimapWithNullKey();
079
080    assertContentsAnyOrder(multimap().removeAll(null), getValueForNullKey());
081
082    expectMissing(mapEntry(null, getValueForNullKey()));
083  }
084
085  @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_ANY_NULL_QUERIES})
086  public void testRemoveAllNullKeyAbsent() {
087    assertEmpty(multimap().removeAll(null));
088    expectUnchanged();
089  }
090}