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. 043public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 044 @MapFeature.Require(SUPPORTS_REMOVE) 045 public void testRemoveAllAbsentKey() { 046 assertEmpty(multimap().removeAll(k3())); 047 expectUnchanged(); 048 } 049 050 @CollectionSize.Require(absent = ZERO) 051 @MapFeature.Require(SUPPORTS_REMOVE) 052 public void testRemoveAllPresentKey() { 053 assertContentsAnyOrder(multimap().removeAll(k0()), v0()); 054 expectMissing(e0()); 055 } 056 057 @CollectionSize.Require(absent = ZERO) 058 @MapFeature.Require(SUPPORTS_REMOVE) 059 public void testRemoveAllPropagatesToGet() { 060 Collection<V> getResult = multimap().get(k0()); 061 062 multimap().removeAll(k0()); 063 064 assertEmpty(getResult); 065 expectMissing(e0()); 066 } 067 068 @CollectionSize.Require(SEVERAL) 069 @MapFeature.Require(SUPPORTS_REMOVE) 070 public void testRemoveAllMultipleValues() { 071 resetContainer( 072 Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2())); 073 074 assertContentsAnyOrder(multimap().removeAll(k0()), v0(), v1(), v2()); 075 assertEmpty(multimap()); 076 } 077 078 @CollectionSize.Require(absent = ZERO) 079 @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS}) 080 public void testRemoveAllNullKeyPresent() { 081 initMultimapWithNullKey(); 082 083 assertContentsAnyOrder(multimap().removeAll(null), getValueForNullKey()); 084 085 expectMissing(Helpers.mapEntry((K) null, getValueForNullKey())); 086 } 087 088 @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_ANY_NULL_QUERIES}) 089 public void testRemoveAllNullKeyAbsent() { 090 assertEmpty(multimap().removeAll(null)); 091 expectUnchanged(); 092 } 093}