Coverage Summary for Class: MultimapClearTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| MultimapClearTester | 0% (0/1) | 0% (0/13) | 0% (0/59) |
1 /* 2 * Copyright (C) 2013 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.assertEmpty; 20 import static com.google.common.collect.testing.features.CollectionSize.ZERO; 21 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 22 import static com.google.common.collect.testing.google.GoogleHelpers.assertEmpty; 23 24 import com.google.common.annotations.GwtCompatible; 25 import com.google.common.collect.Multimap; 26 import com.google.common.collect.testing.features.CollectionSize; 27 import com.google.common.collect.testing.features.MapFeature; 28 import java.util.Collection; 29 import java.util.Map; 30 import java.util.Map.Entry; 31 import org.junit.Ignore; 32 33 /** 34 * Tests for {@link Multimap#clear()}. 35 * 36 * @author Louis Wasserman 37 */ 38 @GwtCompatible 39 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 40 public class MultimapClearTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 41 @CollectionSize.Require(absent = ZERO) 42 @MapFeature.Require(absent = SUPPORTS_REMOVE) 43 public void testClearUnsupported() { 44 try { 45 multimap().clear(); 46 fail("Expected UnsupportedOperationException"); 47 } catch (UnsupportedOperationException expected) { 48 } 49 } 50 51 private void assertCleared() { 52 assertEquals(0, multimap().size()); 53 assertEmpty(multimap()); 54 assertEquals(multimap(), getSubjectGenerator().create()); 55 assertEmpty(multimap().entries()); 56 assertEmpty(multimap().asMap()); 57 assertEmpty(multimap().keySet()); 58 assertEmpty(multimap().keys()); 59 assertEmpty(multimap().values()); 60 for (K key : sampleKeys()) { 61 assertGet(key); 62 } 63 } 64 65 @MapFeature.Require(SUPPORTS_REMOVE) 66 public void testClear() { 67 multimap().clear(); 68 assertCleared(); 69 } 70 71 @MapFeature.Require(SUPPORTS_REMOVE) 72 public void testClearThroughEntries() { 73 multimap().entries().clear(); 74 assertCleared(); 75 } 76 77 @MapFeature.Require(SUPPORTS_REMOVE) 78 public void testClearThroughAsMap() { 79 multimap().asMap().clear(); 80 assertCleared(); 81 } 82 83 @MapFeature.Require(SUPPORTS_REMOVE) 84 public void testClearThroughKeySet() { 85 multimap().keySet().clear(); 86 assertCleared(); 87 } 88 89 @MapFeature.Require(SUPPORTS_REMOVE) 90 public void testClearThroughKeys() { 91 multimap().keys().clear(); 92 assertCleared(); 93 } 94 95 @MapFeature.Require(SUPPORTS_REMOVE) 96 public void testClearThroughValues() { 97 multimap().values().clear(); 98 assertCleared(); 99 } 100 101 @MapFeature.Require(SUPPORTS_REMOVE) 102 @CollectionSize.Require(absent = ZERO) 103 public void testClearPropagatesToGet() { 104 for (K key : sampleKeys()) { 105 resetContainer(); 106 Collection<V> collection = multimap().get(key); 107 multimap().clear(); 108 assertEmpty(collection); 109 } 110 } 111 112 @MapFeature.Require(SUPPORTS_REMOVE) 113 @CollectionSize.Require(absent = ZERO) 114 public void testClearPropagatesToAsMapGet() { 115 for (K key : sampleKeys()) { 116 resetContainer(); 117 Collection<V> collection = multimap().asMap().get(key); 118 if (collection != null) { 119 multimap().clear(); 120 assertEmpty(collection); 121 } 122 } 123 } 124 125 @MapFeature.Require(SUPPORTS_REMOVE) 126 public void testClearPropagatesToAsMap() { 127 Map<K, Collection<V>> asMap = multimap().asMap(); 128 multimap().clear(); 129 assertEmpty(asMap); 130 } 131 132 @MapFeature.Require(SUPPORTS_REMOVE) 133 public void testClearPropagatesToEntries() { 134 Collection<Entry<K, V>> entries = multimap().entries(); 135 multimap().clear(); 136 assertEmpty(entries); 137 } 138 }