Coverage Summary for Class: MultimapPutIterableTester (com.google.common.collect.testing.google)
| Class | Method, % | Line, % |
|---|---|---|
| MultimapPutIterableTester | 0% (0/17) | 0% (0/77) |
| MultimapPutIterableTester$1 | 0% (0/2) | 0% (0/2) |
| MultimapPutIterableTester$2 | 0% (0/2) | 0% (0/2) |
| MultimapPutIterableTester$3 | 0% (0/2) | 0% (0/2) |
| MultimapPutIterableTester$4 | 0% (0/2) | 0% (0/5) |
| Total | 0% (0/25) | 0% (0/88) |
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 package com.google.common.collect.testing.google; 17 18 import static com.google.common.base.Preconditions.checkState; 19 import static com.google.common.collect.testing.Helpers.assertContainsAllOf; 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_VALUES; 23 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; 24 25 import com.google.common.annotations.GwtCompatible; 26 import com.google.common.collect.ImmutableSet; 27 import com.google.common.collect.Iterators; 28 import com.google.common.collect.Lists; 29 import com.google.common.collect.Multimap; 30 import com.google.common.collect.testing.features.CollectionSize; 31 import com.google.common.collect.testing.features.MapFeature; 32 import java.util.Collection; 33 import java.util.Collections; 34 import java.util.Iterator; 35 import org.junit.Ignore; 36 37 /** 38 * Tests for {@link Multimap#putAll(Object, Iterable)}. 39 * 40 * @author Louis Wasserman 41 */ 42 @GwtCompatible 43 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 44 public class MultimapPutIterableTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 45 @CollectionSize.Require(absent = ZERO) 46 @MapFeature.Require(SUPPORTS_PUT) 47 public void testPutAllNonEmptyIterableOnPresentKey() { 48 assertTrue( 49 multimap() 50 .putAll( 51 k0(), 52 new Iterable<V>() { 53 @Override 54 public Iterator<V> iterator() { 55 return Lists.newArrayList(v3(), v4()).iterator(); 56 } 57 })); 58 assertGet(k0(), v0(), v3(), v4()); 59 } 60 61 @CollectionSize.Require(absent = ZERO) 62 @MapFeature.Require(SUPPORTS_PUT) 63 public void testPutAllNonEmptyCollectionOnPresentKey() { 64 assertTrue(multimap().putAll(k0(), Lists.newArrayList(v3(), v4()))); 65 assertGet(k0(), v0(), v3(), v4()); 66 } 67 68 @MapFeature.Require(SUPPORTS_PUT) 69 public void testPutAllNonEmptyIterableOnAbsentKey() { 70 assertTrue( 71 multimap() 72 .putAll( 73 k3(), 74 new Iterable<V>() { 75 @Override 76 public Iterator<V> iterator() { 77 return Lists.newArrayList(v3(), v4()).iterator(); 78 } 79 })); 80 assertGet(k3(), v3(), v4()); 81 } 82 83 @MapFeature.Require(SUPPORTS_PUT) 84 public void testPutAllNonEmptyCollectionOnAbsentKey() { 85 assertTrue(multimap().putAll(k3(), Lists.newArrayList(v3(), v4()))); 86 assertGet(k3(), v3(), v4()); 87 } 88 89 @CollectionSize.Require(absent = ZERO) 90 @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) 91 public void testPutAllNullValueOnPresentKey_supported() { 92 assertTrue(multimap().putAll(k0(), Lists.newArrayList(v3(), null))); 93 assertGet(k0(), v0(), v3(), null); 94 } 95 96 @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) 97 public void testPutAllNullValueOnAbsentKey_supported() { 98 assertTrue(multimap().putAll(k3(), Lists.newArrayList(v3(), null))); 99 assertGet(k3(), v3(), null); 100 } 101 102 @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) 103 public void testPutAllNullValueSingle_unsupported() { 104 multimap().putAll(k1(), Lists.newArrayList((V) null)); 105 expectUnchanged(); 106 } 107 108 // In principle, it would be nice to apply these two tests to keys with existing values, too. 109 110 @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) 111 public void testPutAllNullValueNullLast_unsupported() { 112 int size = getNumElements(); 113 114 try { 115 multimap().putAll(k3(), Lists.newArrayList(v3(), null)); 116 fail(); 117 } catch (NullPointerException expected) { 118 } 119 120 Collection<V> values = multimap().get(k3()); 121 if (values.size() == 0) { 122 expectUnchanged(); 123 // Be extra thorough in case internal state was corrupted by the expected null. 124 assertEquals(Lists.newArrayList(), Lists.newArrayList(values)); 125 assertEquals(size, multimap().size()); 126 } else { 127 assertEquals(Lists.newArrayList(v3()), Lists.newArrayList(values)); 128 assertEquals(size + 1, multimap().size()); 129 } 130 } 131 132 @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) 133 public void testPutAllNullValueNullFirst_unsupported() { 134 int size = getNumElements(); 135 136 try { 137 multimap().putAll(k3(), Lists.newArrayList(null, v3())); 138 fail(); 139 } catch (NullPointerException expected) { 140 } 141 142 /* 143 * In principle, a Multimap implementation could add e3 first before failing on the null. But 144 * that seems unlikely enough to be worth complicating the test over, especially if there's any 145 * chance that a permissive test could mask a bug. 146 */ 147 expectUnchanged(); 148 // Be extra thorough in case internal state was corrupted by the expected null. 149 assertEquals(Lists.newArrayList(), Lists.newArrayList(multimap().get(k3()))); 150 assertEquals(size, multimap().size()); 151 } 152 153 @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) 154 public void testPutAllOnPresentNullKey() { 155 assertTrue(multimap().putAll(null, Lists.newArrayList(v3(), v4()))); 156 assertGet(null, v3(), v4()); 157 } 158 159 @MapFeature.Require(absent = ALLOWS_NULL_KEYS) 160 public void testPutAllNullForbidden() { 161 try { 162 multimap().putAll(null, Collections.singletonList(v3())); 163 fail("Expected NullPointerException"); 164 } catch (NullPointerException expected) { 165 // success 166 } 167 } 168 169 @MapFeature.Require(SUPPORTS_PUT) 170 public void testPutAllEmptyCollectionOnAbsentKey() { 171 assertFalse(multimap().putAll(k3(), Collections.<V>emptyList())); 172 expectUnchanged(); 173 } 174 175 @MapFeature.Require(SUPPORTS_PUT) 176 public void testPutAllEmptyIterableOnAbsentKey() { 177 Iterable<V> iterable = 178 new Iterable<V>() { 179 @Override 180 public Iterator<V> iterator() { 181 return ImmutableSet.<V>of().iterator(); 182 } 183 }; 184 185 assertFalse(multimap().putAll(k3(), iterable)); 186 expectUnchanged(); 187 } 188 189 @CollectionSize.Require(absent = ZERO) 190 @MapFeature.Require(SUPPORTS_PUT) 191 public void testPutAllEmptyIterableOnPresentKey() { 192 multimap().putAll(k0(), Collections.<V>emptyList()); 193 expectUnchanged(); 194 } 195 196 @MapFeature.Require(SUPPORTS_PUT) 197 public void testPutAllOnlyCallsIteratorOnce() { 198 Iterable<V> iterable = 199 new Iterable<V>() { 200 private boolean calledIteratorAlready = false; 201 202 @Override 203 public Iterator<V> iterator() { 204 checkState(!calledIteratorAlready); 205 calledIteratorAlready = true; 206 return Iterators.forArray(v3()); 207 } 208 }; 209 210 multimap().putAll(k3(), iterable); 211 } 212 213 @MapFeature.Require(SUPPORTS_PUT) 214 public void testPutAllPropagatesToGet() { 215 Collection<V> getCollection = multimap().get(k0()); 216 int getCollectionSize = getCollection.size(); 217 assertTrue(multimap().putAll(k0(), Lists.newArrayList(v3(), v4()))); 218 assertEquals(getCollectionSize + 2, getCollection.size()); 219 assertContainsAllOf(getCollection, v3(), v4()); 220 } 221 }