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; 028 029/** 030 * Tester for {@code BiMap.remove}. 031 * 032 * @author Louis Wasserman 033 */ 034@GwtCompatible 035public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> { 036 @MapFeature.Require(SUPPORTS_REMOVE) 037 @CollectionSize.Require(absent = ZERO) 038 public void testRemoveKeyRemovesFromInverse() { 039 getMap().remove(k0()); 040 expectMissing(e0()); 041 } 042 043 @MapFeature.Require(SUPPORTS_REMOVE) 044 @CollectionSize.Require(absent = ZERO) 045 public void testRemoveKeyFromKeySetRemovesFromInverse() { 046 getMap().keySet().remove(k0()); 047 expectMissing(e0()); 048 } 049 050 @MapFeature.Require(SUPPORTS_REMOVE) 051 @CollectionSize.Require(absent = ZERO) 052 public void testRemoveFromValuesRemovesFromInverse() { 053 getMap().values().remove(v0()); 054 expectMissing(e0()); 055 } 056 057 @MapFeature.Require(SUPPORTS_REMOVE) 058 @CollectionSize.Require(absent = ZERO) 059 public void testRemoveFromInverseRemovesFromForward() { 060 getMap().inverse().remove(v0()); 061 expectMissing(e0()); 062 } 063 064 @MapFeature.Require(SUPPORTS_REMOVE) 065 @CollectionSize.Require(absent = ZERO) 066 public void testRemoveFromInverseKeySetRemovesFromForward() { 067 getMap().inverse().keySet().remove(v0()); 068 expectMissing(e0()); 069 } 070 071 @MapFeature.Require(SUPPORTS_REMOVE) 072 @CollectionSize.Require(absent = ZERO) 073 public void testRemoveFromInverseValuesRemovesFromInverse() { 074 getMap().inverse().values().remove(k0()); 075 expectMissing(e0()); 076 } 077 078 @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) 079 @CollectionSize.Require(absent = ZERO) 080 public void testKeySetIteratorRemove() { 081 int initialSize = getNumElements(); 082 Iterator<K> iterator = getMap().keySet().iterator(); 083 iterator.next(); 084 iterator.remove(); 085 assertEquals(initialSize - 1, getMap().size()); 086 assertEquals(initialSize - 1, getMap().inverse().size()); 087 } 088}