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.MapFeature.SUPPORTS_REMOVE;
020
021import com.google.common.annotations.GwtCompatible;
022import com.google.common.collect.BiMap;
023import com.google.common.collect.testing.features.MapFeature;
024import org.junit.Ignore;
025
026/**
027 * Tester for {@code BiMap.clear}.
028 *
029 * @author Louis Wasserman
030 */
031@GwtCompatible
032@Ignore("test runners must not instantiate and run this directly, only via suites we build")
033// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
034@SuppressWarnings("JUnit4ClassUsedInJUnit3")
035public class BiMapClearTester<K, V> extends AbstractBiMapTester<K, V> {
036  @MapFeature.Require(SUPPORTS_REMOVE)
037  public void testClearClearsInverse() {
038    BiMap<V, K> inv = getMap().inverse();
039    getMap().clear();
040    assertTrue(getMap().isEmpty());
041    assertTrue(inv.isEmpty());
042  }
043
044  @MapFeature.Require(SUPPORTS_REMOVE)
045  public void testKeySetClearClearsInverse() {
046    BiMap<V, K> inv = getMap().inverse();
047    getMap().keySet().clear();
048    assertTrue(getMap().isEmpty());
049    assertTrue(inv.isEmpty());
050  }
051
052  @MapFeature.Require(SUPPORTS_REMOVE)
053  public void testValuesClearClearsInverse() {
054    BiMap<V, K> inv = getMap().inverse();
055    getMap().values().clear();
056    assertTrue(getMap().isEmpty());
057    assertTrue(inv.isEmpty());
058  }
059
060  @MapFeature.Require(SUPPORTS_REMOVE)
061  public void testClearInverseClears() {
062    BiMap<V, K> inv = getMap().inverse();
063    inv.clear();
064    assertTrue(getMap().isEmpty());
065    assertTrue(inv.isEmpty());
066  }
067
068  @MapFeature.Require(SUPPORTS_REMOVE)
069  public void testClearInverseKeySetClears() {
070    BiMap<V, K> inv = getMap().inverse();
071    inv.keySet().clear();
072    assertTrue(getMap().isEmpty());
073    assertTrue(inv.isEmpty());
074  }
075
076  @MapFeature.Require(SUPPORTS_REMOVE)
077  public void testClearInverseValuesClears() {
078    BiMap<V, K> inv = getMap().inverse();
079    inv.values().clear();
080    assertTrue(getMap().isEmpty());
081    assertTrue(inv.isEmpty());
082  }
083}