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  @SuppressWarnings("unchecked")
039  @MapFeature.Require(SUPPORTS_REMOVE)
040  @CollectionSize.Require(absent = ZERO)
041  public void testRemoveKeyRemovesFromInverse() {
042    getMap().remove(k0());
043    expectMissing(e0());
044  }
045
046  @SuppressWarnings("unchecked")
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  @SuppressWarnings("unchecked")
055  @MapFeature.Require(SUPPORTS_REMOVE)
056  @CollectionSize.Require(absent = ZERO)
057  public void testRemoveFromValuesRemovesFromInverse() {
058    getMap().values().remove(v0());
059    expectMissing(e0());
060  }
061
062  @SuppressWarnings("unchecked")
063  @MapFeature.Require(SUPPORTS_REMOVE)
064  @CollectionSize.Require(absent = ZERO)
065  public void testRemoveFromInverseRemovesFromForward() {
066    getMap().inverse().remove(v0());
067    expectMissing(e0());
068  }
069
070  @SuppressWarnings("unchecked")
071  @MapFeature.Require(SUPPORTS_REMOVE)
072  @CollectionSize.Require(absent = ZERO)
073  public void testRemoveFromInverseKeySetRemovesFromForward() {
074    getMap().inverse().keySet().remove(v0());
075    expectMissing(e0());
076  }
077
078  @SuppressWarnings("unchecked")
079  @MapFeature.Require(SUPPORTS_REMOVE)
080  @CollectionSize.Require(absent = ZERO)
081  public void testRemoveFromInverseValuesRemovesFromInverse() {
082    getMap().inverse().values().remove(k0());
083    expectMissing(e0());
084  }
085
086  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
087  @CollectionSize.Require(absent = ZERO)
088  public void testKeySetIteratorRemove() {
089    int initialSize = getNumElements();
090    Iterator<K> iterator = getMap().keySet().iterator();
091    iterator.next();
092    iterator.remove();
093    assertEquals(initialSize - 1, getMap().size());
094    assertEquals(initialSize - 1, getMap().inverse().size());
095  }
096}