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.Helpers.assertContentsAnyOrder;
20  import static com.google.common.collect.testing.Helpers.assertEmpty;
21  import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
22  import static com.google.common.collect.testing.features.CollectionSize.ZERO;
23  import static com.google.common.collect.testing.features.MapFeature.ALLOWS_ANY_NULL_QUERIES;
24  import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
25  import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
26  import static com.google.common.collect.testing.google.GoogleHelpers.assertEmpty;
27  
28  import com.google.common.annotations.GwtCompatible;
29  import com.google.common.collect.Multimap;
30  import com.google.common.collect.testing.Helpers;
31  import com.google.common.collect.testing.features.CollectionSize;
32  import com.google.common.collect.testing.features.MapFeature;
33  import java.util.Collection;
34  
35  /**
36   * Tests for {@link Multimap#removeAll(Object)}.
37   *
38   * @author Louis Wasserman
39   */
40  @GwtCompatible
41  public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
42    @MapFeature.Require(SUPPORTS_REMOVE)
43    public void testRemoveAllAbsentKey() {
44      assertEmpty(multimap().removeAll(k3()));
45      expectUnchanged();
46    }
47  
48    @CollectionSize.Require(absent = ZERO)
49    @MapFeature.Require(SUPPORTS_REMOVE)
50    public void testRemoveAllPresentKey() {
51      assertContentsAnyOrder(multimap().removeAll(k0()), v0());
52      expectMissing(e0());
53    }
54  
55    @CollectionSize.Require(absent = ZERO)
56    @MapFeature.Require(SUPPORTS_REMOVE)
57    public void testRemoveAllPropagatesToGet() {
58      Collection<V> getResult = multimap().get(k0());
59  
60      multimap().removeAll(k0());
61  
62      assertEmpty(getResult);
63      expectMissing(e0());
64    }
65  
66    @CollectionSize.Require(SEVERAL)
67    @MapFeature.Require(SUPPORTS_REMOVE)
68    public void testRemoveAllMultipleValues() {
69      resetContainer(
70          Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2()));
71  
72      assertContentsAnyOrder(multimap().removeAll(k0()), v0(), v1(), v2());
73      assertEmpty(multimap());
74    }
75  
76    @CollectionSize.Require(absent = ZERO)
77    @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS})
78    public void testRemoveAllNullKeyPresent() {
79      initMultimapWithNullKey();
80  
81      assertContentsAnyOrder(multimap().removeAll(null), getValueForNullKey());
82  
83      expectMissing(Helpers.mapEntry((K) null, getValueForNullKey()));
84    }
85  
86    @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_ANY_NULL_QUERIES})
87    public void testRemoveAllNullKeyAbsent() {
88      assertEmpty(multimap().removeAll(null));
89      expectUnchanged();
90    }
91  }