Coverage Summary for Class: MultimapRemoveEntryTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| MultimapRemoveEntryTester | 0% (0/1) | 0% (0/12) | 0% (0/87) |
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.assertEqualIgnoringOrder; 20 import static com.google.common.collect.testing.features.CollectionSize.ZERO; 21 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS; 22 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEY_QUERIES; 23 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES; 24 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUE_QUERIES; 25 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 26 27 import com.google.common.annotations.GwtCompatible; 28 import com.google.common.collect.ImmutableList; 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 import java.util.Iterator; 35 import java.util.List; 36 import java.util.Map.Entry; 37 import org.junit.Ignore; 38 39 /** 40 * Tests for {@link Multimap#remove(Object, Object)}. 41 * 42 * @author Louis Wasserman 43 */ 44 @GwtCompatible 45 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 46 public class MultimapRemoveEntryTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 47 @MapFeature.Require(SUPPORTS_REMOVE) 48 public void testRemoveAbsent() { 49 assertFalse(multimap().remove(k0(), v1())); 50 expectUnchanged(); 51 } 52 53 @CollectionSize.Require(absent = ZERO) 54 @MapFeature.Require(SUPPORTS_REMOVE) 55 public void testRemovePresent() { 56 assertTrue(multimap().remove(k0(), v0())); 57 58 assertFalse(multimap().containsEntry(k0(), v0())); 59 expectMissing(e0()); 60 assertEquals(getNumElements() - 1, multimap().size()); 61 assertGet(k0(), ImmutableList.<V>of()); 62 } 63 64 @CollectionSize.Require(absent = ZERO) 65 @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS}) 66 public void testRemoveNullKeyPresent() { 67 initMultimapWithNullKey(); 68 69 assertTrue(multimap().remove(null, getValueForNullKey())); 70 71 expectMissing(Helpers.mapEntry((K) null, getValueForNullKey())); 72 assertGet(getKeyForNullValue(), ImmutableList.<V>of()); 73 } 74 75 @CollectionSize.Require(absent = ZERO) 76 @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES}) 77 public void testRemoveNullValuePresent() { 78 initMultimapWithNullValue(); 79 80 assertTrue(multimap().remove(getKeyForNullValue(), null)); 81 82 expectMissing(Helpers.mapEntry(getKeyForNullValue(), (V) null)); 83 assertGet(getKeyForNullValue(), ImmutableList.<V>of()); 84 } 85 86 @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEY_QUERIES}) 87 public void testRemoveNullKeyAbsent() { 88 assertFalse(multimap().remove(null, v0())); 89 expectUnchanged(); 90 } 91 92 @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUE_QUERIES}) 93 public void testRemoveNullValueAbsent() { 94 assertFalse(multimap().remove(k0(), null)); 95 expectUnchanged(); 96 } 97 98 @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_VALUE_QUERIES) 99 public void testRemoveNullValueForbidden() { 100 try { 101 multimap().remove(k0(), null); 102 fail("Expected NullPointerException"); 103 } catch (NullPointerException expected) { 104 // success 105 } 106 expectUnchanged(); 107 } 108 109 @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES) 110 public void testRemoveNullKeyForbidden() { 111 try { 112 multimap().remove(null, v0()); 113 fail("Expected NullPointerException"); 114 } catch (NullPointerException expected) { 115 // success 116 } 117 expectUnchanged(); 118 } 119 120 @MapFeature.Require(SUPPORTS_REMOVE) 121 @CollectionSize.Require(absent = ZERO) 122 public void testRemovePropagatesToGet() { 123 List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries()); 124 for (Entry<K, V> entry : entries) { 125 resetContainer(); 126 127 K key = entry.getKey(); 128 V value = entry.getValue(); 129 Collection<V> collection = multimap().get(key); 130 assertNotNull(collection); 131 Collection<V> expectedCollection = Helpers.copyToList(collection); 132 133 multimap().remove(key, value); 134 expectedCollection.remove(value); 135 136 assertEqualIgnoringOrder(expectedCollection, collection); 137 assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key)); 138 } 139 } 140 141 @MapFeature.Require(SUPPORTS_REMOVE) 142 @CollectionSize.Require(absent = ZERO) 143 public void testRemovePropagatesToAsMap() { 144 List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries()); 145 for (Entry<K, V> entry : entries) { 146 resetContainer(); 147 148 K key = entry.getKey(); 149 V value = entry.getValue(); 150 Collection<V> collection = multimap().asMap().get(key); 151 assertNotNull(collection); 152 Collection<V> expectedCollection = Helpers.copyToList(collection); 153 154 multimap().remove(key, value); 155 expectedCollection.remove(value); 156 157 assertEqualIgnoringOrder(expectedCollection, collection); 158 assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key)); 159 } 160 } 161 162 @MapFeature.Require(SUPPORTS_REMOVE) 163 @CollectionSize.Require(absent = ZERO) 164 public void testRemovePropagatesToAsMapEntrySet() { 165 List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries()); 166 for (Entry<K, V> entry : entries) { 167 resetContainer(); 168 169 K key = entry.getKey(); 170 V value = entry.getValue(); 171 172 Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator(); 173 Collection<V> collection = null; 174 while (asMapItr.hasNext()) { 175 Entry<K, Collection<V>> asMapEntry = asMapItr.next(); 176 if (key.equals(asMapEntry.getKey())) { 177 collection = asMapEntry.getValue(); 178 break; 179 } 180 } 181 assertNotNull(collection); 182 Collection<V> expectedCollection = Helpers.copyToList(collection); 183 184 multimap().remove(key, value); 185 expectedCollection.remove(value); 186 187 assertEqualIgnoringOrder(expectedCollection, collection); 188 assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key)); 189 } 190 } 191 }