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