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; 034import org.junit.Ignore; 035 036/** 037 * Tests for {@link Multimap#removeAll(Object)}. 038 * 039 * @author Louis Wasserman 040 */ 041@GwtCompatible 042@Ignore("test runners must not instantiate and run this directly, only via suites we build") 043// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 044@SuppressWarnings("JUnit4ClassUsedInJUnit3") 045public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 046 @MapFeature.Require(SUPPORTS_REMOVE) 047 public void testRemoveAllAbsentKey() { 048 assertEmpty(multimap().removeAll(k3())); 049 expectUnchanged(); 050 } 051 052 @CollectionSize.Require(absent = ZERO) 053 @MapFeature.Require(SUPPORTS_REMOVE) 054 public void testRemoveAllPresentKey() { 055 assertContentsAnyOrder(multimap().removeAll(k0()), v0()); 056 expectMissing(e0()); 057 } 058 059 @CollectionSize.Require(absent = ZERO) 060 @MapFeature.Require(SUPPORTS_REMOVE) 061 public void testRemoveAllPropagatesToGet() { 062 Collection<V> getResult = multimap().get(k0()); 063 064 multimap().removeAll(k0()); 065 066 assertEmpty(getResult); 067 expectMissing(e0()); 068 } 069 070 @CollectionSize.Require(SEVERAL) 071 @MapFeature.Require(SUPPORTS_REMOVE) 072 public void testRemoveAllMultipleValues() { 073 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), 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(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}