• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 import java.util.Iterator;
29 
30 /**
31  * Tester for {@code BiMap.remove}.
32  *
33  * @author Louis Wasserman
34  */
35 @GwtCompatible
36 public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> {
37   @SuppressWarnings("unchecked")
38   @MapFeature.Require(SUPPORTS_REMOVE)
39   @CollectionSize.Require(absent = ZERO)
testRemoveKeyRemovesFromInverse()40   public void testRemoveKeyRemovesFromInverse() {
41     getMap().remove(samples.e0.getKey());
42     expectMissing(samples.e0);
43   }
44 
45   @SuppressWarnings("unchecked")
46   @MapFeature.Require(SUPPORTS_REMOVE)
47   @CollectionSize.Require(absent = ZERO)
testRemoveKeyFromKeySetRemovesFromInverse()48   public void testRemoveKeyFromKeySetRemovesFromInverse() {
49     getMap().keySet().remove(samples.e0.getKey());
50     expectMissing(samples.e0);
51   }
52 
53   @SuppressWarnings("unchecked")
54   @MapFeature.Require(SUPPORTS_REMOVE)
55   @CollectionSize.Require(absent = ZERO)
testRemoveFromValuesRemovesFromInverse()56   public void testRemoveFromValuesRemovesFromInverse() {
57     getMap().values().remove(samples.e0.getValue());
58     expectMissing(samples.e0);
59   }
60 
61   @SuppressWarnings("unchecked")
62   @MapFeature.Require(SUPPORTS_REMOVE)
63   @CollectionSize.Require(absent = ZERO)
testRemoveFromInverseRemovesFromForward()64   public void testRemoveFromInverseRemovesFromForward() {
65     getMap().inverse().remove(samples.e0.getValue());
66     expectMissing(samples.e0);
67   }
68 
69   @SuppressWarnings("unchecked")
70   @MapFeature.Require(SUPPORTS_REMOVE)
71   @CollectionSize.Require(absent = ZERO)
testRemoveFromInverseKeySetRemovesFromForward()72   public void testRemoveFromInverseKeySetRemovesFromForward() {
73     getMap().inverse().keySet().remove(samples.e0.getValue());
74     expectMissing(samples.e0);
75   }
76 
77   @SuppressWarnings("unchecked")
78   @MapFeature.Require(SUPPORTS_REMOVE)
79   @CollectionSize.Require(absent = ZERO)
testRemoveFromInverseValuesRemovesFromInverse()80   public void testRemoveFromInverseValuesRemovesFromInverse() {
81     getMap().inverse().values().remove(samples.e0.getKey());
82     expectMissing(samples.e0);
83   }
84 
85   @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
86   @CollectionSize.Require(absent = ZERO)
testKeySetIteratorRemove()87   public void testKeySetIteratorRemove() {
88     int initialSize = getNumElements();
89     Iterator<K> iterator = getMap().keySet().iterator();
90     iterator.next();
91     iterator.remove();
92     assertEquals(initialSize - 1, getMap().size());
93     assertEquals(initialSize - 1, getMap().inverse().size());
94   }
95 }
96