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.features.CollectionFeature.SUPPORTS_ITERATOR_REMOVE; 020import static com.google.common.collect.testing.features.CollectionSize.ZERO; 021import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 022 023import com.google.common.annotations.GwtCompatible; 024import com.google.common.collect.testing.features.CollectionFeature; 025import com.google.common.collect.testing.features.CollectionSize; 026import com.google.common.collect.testing.features.MapFeature; 027import java.util.Iterator; 028import org.junit.Ignore; 029 030/** 031 * Tester for {@code BiMap.remove}. 032 * 033 * @author Louis Wasserman 034 */ 035@GwtCompatible 036@Ignore("test runners must not instantiate and run this directly, only via suites we build") 037// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 038@SuppressWarnings("JUnit4ClassUsedInJUnit3") 039public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> { 040 @MapFeature.Require(SUPPORTS_REMOVE) 041 @CollectionSize.Require(absent = ZERO) 042 public void testRemoveKeyRemovesFromInverse() { 043 getMap().remove(k0()); 044 expectMissing(e0()); 045 } 046 047 @MapFeature.Require(SUPPORTS_REMOVE) 048 @CollectionSize.Require(absent = ZERO) 049 public void testRemoveKeyFromKeySetRemovesFromInverse() { 050 getMap().keySet().remove(k0()); 051 expectMissing(e0()); 052 } 053 054 @MapFeature.Require(SUPPORTS_REMOVE) 055 @CollectionSize.Require(absent = ZERO) 056 public void testRemoveFromValuesRemovesFromInverse() { 057 getMap().values().remove(v0()); 058 expectMissing(e0()); 059 } 060 061 @MapFeature.Require(SUPPORTS_REMOVE) 062 @CollectionSize.Require(absent = ZERO) 063 public void testRemoveFromInverseRemovesFromForward() { 064 getMap().inverse().remove(v0()); 065 expectMissing(e0()); 066 } 067 068 @MapFeature.Require(SUPPORTS_REMOVE) 069 @CollectionSize.Require(absent = ZERO) 070 public void testRemoveFromInverseKeySetRemovesFromForward() { 071 getMap().inverse().keySet().remove(v0()); 072 expectMissing(e0()); 073 } 074 075 @MapFeature.Require(SUPPORTS_REMOVE) 076 @CollectionSize.Require(absent = ZERO) 077 public void testRemoveFromInverseValuesRemovesFromInverse() { 078 getMap().inverse().values().remove(k0()); 079 expectMissing(e0()); 080 } 081 082 @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) 083 @CollectionSize.Require(absent = ZERO) 084 public void testKeySetIteratorRemove() { 085 int initialSize = getNumElements(); 086 Iterator<K> iterator = getMap().keySet().iterator(); 087 iterator.next(); 088 iterator.remove(); 089 assertEquals(initialSize - 1, getMap().size()); 090 assertEquals(initialSize - 1, getMap().inverse().size()); 091 } 092}