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