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.features.CollectionSize.SEVERAL;
022import static com.google.common.collect.testing.features.CollectionSize.ZERO;
023import static com.google.common.collect.testing.features.MapFeature.ALLOWS_ANY_NULL_QUERIES;
024import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
025import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
026import static com.google.common.collect.testing.google.GoogleHelpers.assertEmpty;
027
028import com.google.common.annotations.GwtCompatible;
029import com.google.common.collect.Multimap;
030import com.google.common.collect.testing.Helpers;
031import com.google.common.collect.testing.features.CollectionSize;
032import com.google.common.collect.testing.features.MapFeature;
033import java.util.Collection;
034import org.junit.Ignore;
035
036/**
037 * Tests for {@link Multimap#removeAll(Object)}.
038 *
039 * @author Louis Wasserman
040 */
041@GwtCompatible
042@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
043@SuppressWarnings("JUnit4ClassUsedInJUnit3")
044public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
045  @MapFeature.Require(SUPPORTS_REMOVE)
046  public void testRemoveAllAbsentKey() {
047    assertEmpty(multimap().removeAll(k3()));
048    expectUnchanged();
049  }
050
051  @CollectionSize.Require(absent = ZERO)
052  @MapFeature.Require(SUPPORTS_REMOVE)
053  public void testRemoveAllPresentKey() {
054    assertContentsAnyOrder(multimap().removeAll(k0()), v0());
055    expectMissing(e0());
056  }
057
058  @CollectionSize.Require(absent = ZERO)
059  @MapFeature.Require(SUPPORTS_REMOVE)
060  public void testRemoveAllPropagatesToGet() {
061    Collection<V> getResult = multimap().get(k0());
062
063    multimap().removeAll(k0());
064
065    assertEmpty(getResult);
066    expectMissing(e0());
067  }
068
069  @CollectionSize.Require(SEVERAL)
070  @MapFeature.Require(SUPPORTS_REMOVE)
071  public void testRemoveAllMultipleValues() {
072    resetContainer(
073        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2()));
074
075    assertContentsAnyOrder(multimap().removeAll(k0()), v0(), v1(), v2());
076    assertEmpty(multimap());
077  }
078
079  @CollectionSize.Require(absent = ZERO)
080  @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS})
081  public void testRemoveAllNullKeyPresent() {
082    initMultimapWithNullKey();
083
084    assertContentsAnyOrder(multimap().removeAll(null), getValueForNullKey());
085
086    expectMissing(Helpers.mapEntry((K) null, getValueForNullKey()));
087  }
088
089  @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_ANY_NULL_QUERIES})
090  public void testRemoveAllNullKeyAbsent() {
091    assertEmpty(multimap().removeAll(null));
092    expectUnchanged();
093  }
094}