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 // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
037public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> {
038  @MapFeature.Require(SUPPORTS_REMOVE)
039  @CollectionSize.Require(absent = ZERO)
040  public void testRemoveKeyRemovesFromInverse() {
041    getMap().remove(k0());
042    expectMissing(e0());
043  }
044
045  @MapFeature.Require(SUPPORTS_REMOVE)
046  @CollectionSize.Require(absent = ZERO)
047  public void testRemoveKeyFromKeySetRemovesFromInverse() {
048    getMap().keySet().remove(k0());
049    expectMissing(e0());
050  }
051
052  @MapFeature.Require(SUPPORTS_REMOVE)
053  @CollectionSize.Require(absent = ZERO)
054  public void testRemoveFromValuesRemovesFromInverse() {
055    getMap().values().remove(v0());
056    expectMissing(e0());
057  }
058
059  @MapFeature.Require(SUPPORTS_REMOVE)
060  @CollectionSize.Require(absent = ZERO)
061  public void testRemoveFromInverseRemovesFromForward() {
062    getMap().inverse().remove(v0());
063    expectMissing(e0());
064  }
065
066  @MapFeature.Require(SUPPORTS_REMOVE)
067  @CollectionSize.Require(absent = ZERO)
068  public void testRemoveFromInverseKeySetRemovesFromForward() {
069    getMap().inverse().keySet().remove(v0());
070    expectMissing(e0());
071  }
072
073  @MapFeature.Require(SUPPORTS_REMOVE)
074  @CollectionSize.Require(absent = ZERO)
075  public void testRemoveFromInverseValuesRemovesFromInverse() {
076    getMap().inverse().values().remove(k0());
077    expectMissing(e0());
078  }
079
080  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
081  @CollectionSize.Require(absent = ZERO)
082  public void testKeySetIteratorRemove() {
083    int initialSize = getNumElements();
084    Iterator<K> iterator = getMap().keySet().iterator();
085    iterator.next();
086    iterator.remove();
087    assertEquals(initialSize - 1, getMap().size());
088    assertEquals(initialSize - 1, getMap().inverse().size());
089  }
090}