View Javadoc
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  
17  package com.google.common.collect.testing.google;
18  
19  import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ITERATOR_REMOVE;
20  import static com.google.common.collect.testing.features.CollectionSize.ZERO;
21  import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
22  
23  import com.google.common.annotations.GwtCompatible;
24  import com.google.common.collect.testing.features.CollectionFeature;
25  import com.google.common.collect.testing.features.CollectionSize;
26  import com.google.common.collect.testing.features.MapFeature;
27  import java.util.Iterator;
28  
29  /**
30   * Tester for {@code BiMap.remove}.
31   *
32   * @author Louis Wasserman
33   */
34  @GwtCompatible
35  public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> {
36    @SuppressWarnings("unchecked")
37    @MapFeature.Require(SUPPORTS_REMOVE)
38    @CollectionSize.Require(absent = ZERO)
39    public void testRemoveKeyRemovesFromInverse() {
40      getMap().remove(k0());
41      expectMissing(e0());
42    }
43  
44    @SuppressWarnings("unchecked")
45    @MapFeature.Require(SUPPORTS_REMOVE)
46    @CollectionSize.Require(absent = ZERO)
47    public void testRemoveKeyFromKeySetRemovesFromInverse() {
48      getMap().keySet().remove(k0());
49      expectMissing(e0());
50    }
51  
52    @SuppressWarnings("unchecked")
53    @MapFeature.Require(SUPPORTS_REMOVE)
54    @CollectionSize.Require(absent = ZERO)
55    public void testRemoveFromValuesRemovesFromInverse() {
56      getMap().values().remove(v0());
57      expectMissing(e0());
58    }
59  
60    @SuppressWarnings("unchecked")
61    @MapFeature.Require(SUPPORTS_REMOVE)
62    @CollectionSize.Require(absent = ZERO)
63    public void testRemoveFromInverseRemovesFromForward() {
64      getMap().inverse().remove(v0());
65      expectMissing(e0());
66    }
67  
68    @SuppressWarnings("unchecked")
69    @MapFeature.Require(SUPPORTS_REMOVE)
70    @CollectionSize.Require(absent = ZERO)
71    public void testRemoveFromInverseKeySetRemovesFromForward() {
72      getMap().inverse().keySet().remove(v0());
73      expectMissing(e0());
74    }
75  
76    @SuppressWarnings("unchecked")
77    @MapFeature.Require(SUPPORTS_REMOVE)
78    @CollectionSize.Require(absent = ZERO)
79    public void testRemoveFromInverseValuesRemovesFromInverse() {
80      getMap().inverse().values().remove(k0());
81      expectMissing(e0());
82    }
83  
84    @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
85    @CollectionSize.Require(absent = ZERO)
86    public void testKeySetIteratorRemove() {
87      int initialSize = getNumElements();
88      Iterator<K> iterator = getMap().keySet().iterator();
89      iterator.next();
90      iterator.remove();
91      assertEquals(initialSize - 1, getMap().size());
92      assertEquals(initialSize - 1, getMap().inverse().size());
93    }
94  }