1/*
2 * Copyright (C) 2012 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.collect.testing.google;
18
19import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
20
21import com.google.common.annotations.GwtCompatible;
22import com.google.common.collect.BiMap;
23import com.google.common.collect.testing.features.MapFeature;
24
25/**
26 * Tester for {@code BiMap.clear}.
27 *
28 * @author Louis Wasserman
29 */
30@GwtCompatible
31public class BiMapClearTester<K, V> extends AbstractBiMapTester<K, V> {
32  @MapFeature.Require(SUPPORTS_REMOVE)
33  public void testClearClearsInverse() {
34    BiMap<V, K> inv = getMap().inverse();
35    getMap().clear();
36    assertTrue(getMap().isEmpty());
37    assertTrue(inv.isEmpty());
38  }
39
40  @MapFeature.Require(SUPPORTS_REMOVE)
41  public void testKeySetClearClearsInverse() {
42    BiMap<V, K> inv = getMap().inverse();
43    getMap().keySet().clear();
44    assertTrue(getMap().isEmpty());
45    assertTrue(inv.isEmpty());
46  }
47
48  @MapFeature.Require(SUPPORTS_REMOVE)
49  public void testValuesClearClearsInverse() {
50    BiMap<V, K> inv = getMap().inverse();
51    getMap().values().clear();
52    assertTrue(getMap().isEmpty());
53    assertTrue(inv.isEmpty());
54  }
55
56  @MapFeature.Require(SUPPORTS_REMOVE)
57  public void testClearInverseClears() {
58    BiMap<V, K> inv = getMap().inverse();
59    inv.clear();
60    assertTrue(getMap().isEmpty());
61    assertTrue(inv.isEmpty());
62  }
63
64  @MapFeature.Require(SUPPORTS_REMOVE)
65  public void testClearInverseKeySetClears() {
66    BiMap<V, K> inv = getMap().inverse();
67    inv.keySet().clear();
68    assertTrue(getMap().isEmpty());
69    assertTrue(inv.isEmpty());
70  }
71
72  @MapFeature.Require(SUPPORTS_REMOVE)
73  public void testClearInverseValuesClears() {
74    BiMap<V, K> inv = getMap().inverse();
75    inv.values().clear();
76    assertTrue(getMap().isEmpty());
77    assertTrue(inv.isEmpty());
78  }
79}
80