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; 024 025/** 026 * Tester for {@code BiMap.clear}. 027 * 028 * @author Louis Wasserman 029 */ 030@GwtCompatible 031public class BiMapClearTester<K, V> extends AbstractBiMapTester<K, V> { 032 @MapFeature.Require(SUPPORTS_REMOVE) 033 public void testClearClearsInverse() { 034 BiMap<V, K> inv = getMap().inverse(); 035 getMap().clear(); 036 assertTrue(getMap().isEmpty()); 037 assertTrue(inv.isEmpty()); 038 } 039 040 @MapFeature.Require(SUPPORTS_REMOVE) 041 public void testKeySetClearClearsInverse() { 042 BiMap<V, K> inv = getMap().inverse(); 043 getMap().keySet().clear(); 044 assertTrue(getMap().isEmpty()); 045 assertTrue(inv.isEmpty()); 046 } 047 048 @MapFeature.Require(SUPPORTS_REMOVE) 049 public void testValuesClearClearsInverse() { 050 BiMap<V, K> inv = getMap().inverse(); 051 getMap().values().clear(); 052 assertTrue(getMap().isEmpty()); 053 assertTrue(inv.isEmpty()); 054 } 055 056 @MapFeature.Require(SUPPORTS_REMOVE) 057 public void testClearInverseClears() { 058 BiMap<V, K> inv = getMap().inverse(); 059 inv.clear(); 060 assertTrue(getMap().isEmpty()); 061 assertTrue(inv.isEmpty()); 062 } 063 064 @MapFeature.Require(SUPPORTS_REMOVE) 065 public void testClearInverseKeySetClears() { 066 BiMap<V, K> inv = getMap().inverse(); 067 inv.keySet().clear(); 068 assertTrue(getMap().isEmpty()); 069 assertTrue(inv.isEmpty()); 070 } 071 072 @MapFeature.Require(SUPPORTS_REMOVE) 073 public void testClearInverseValuesClears() { 074 BiMap<V, K> inv = getMap().inverse(); 075 inv.values().clear(); 076 assertTrue(getMap().isEmpty()); 077 assertTrue(inv.isEmpty()); 078 } 079}