Coverage Summary for Class: MultimapGetTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| MultimapGetTester | 0% (0/1) | 0% (0/14) | 0% (0/66) |
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.collect.testing.Helpers.assertContains; 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_NULL_KEYS; 24 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEY_QUERIES; 25 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES; 26 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; 27 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 28 29 import com.google.common.annotations.GwtCompatible; 30 import com.google.common.collect.Multimap; 31 import com.google.common.collect.testing.Helpers; 32 import com.google.common.collect.testing.features.CollectionSize; 33 import com.google.common.collect.testing.features.MapFeature; 34 import java.util.Collection; 35 import java.util.Collections; 36 import org.junit.Ignore; 37 38 /** 39 * Tests for {@link Multimap#get(Object)}. 40 * 41 * @author Louis Wasserman 42 */ 43 @GwtCompatible 44 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 45 public class MultimapGetTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 46 public void testGetEmpty() { 47 Collection<V> result = multimap().get(k3()); 48 assertEmpty(result); 49 assertEquals(0, result.size()); 50 } 51 52 @CollectionSize.Require(absent = ZERO) 53 public void testGetNonEmpty() { 54 Collection<V> result = multimap().get(k0()); 55 assertFalse(result.isEmpty()); 56 assertContentsAnyOrder(result, v0()); 57 } 58 59 @CollectionSize.Require(SEVERAL) 60 public void testGetMultiple() { 61 resetContainer( 62 Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2())); 63 assertGet(k0(), v0(), v1(), v2()); 64 } 65 66 public void testGetAbsentKey() { 67 assertGet(k4()); 68 } 69 70 @CollectionSize.Require(SEVERAL) 71 @MapFeature.Require(SUPPORTS_REMOVE) 72 public void testPropagatesRemoveToMultimap() { 73 resetContainer( 74 Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v3()), Helpers.mapEntry(k0(), v2())); 75 Collection<V> result = multimap().get(k0()); 76 assertTrue(result.remove(v0())); 77 assertFalse(multimap().containsEntry(k0(), v0())); 78 assertEquals(2, multimap().size()); 79 } 80 81 @CollectionSize.Require(absent = ZERO) 82 @MapFeature.Require(SUPPORTS_REMOVE) 83 public void testPropagatesRemoveLastElementToMultimap() { 84 Collection<V> result = multimap().get(k0()); 85 assertTrue(result.remove(v0())); 86 assertGet(k0()); 87 } 88 89 @MapFeature.Require(SUPPORTS_PUT) 90 public void testPropagatesAddToMultimap() { 91 Collection<V> result = multimap().get(k0()); 92 assertTrue(result.add(v3())); 93 assertTrue(multimap().containsKey(k0())); 94 assertEquals(getNumElements() + 1, multimap().size()); 95 assertTrue(multimap().containsEntry(k0(), v3())); 96 } 97 98 @MapFeature.Require(SUPPORTS_PUT) 99 public void testPropagatesAddAllToMultimap() { 100 Collection<V> result = multimap().get(k0()); 101 assertTrue(result.addAll(Collections.singletonList(v3()))); 102 assertTrue(multimap().containsKey(k0())); 103 assertEquals(getNumElements() + 1, multimap().size()); 104 assertTrue(multimap().containsEntry(k0(), v3())); 105 } 106 107 @CollectionSize.Require(absent = ZERO) 108 @MapFeature.Require({SUPPORTS_REMOVE, SUPPORTS_PUT}) 109 public void testPropagatesRemoveLastThenAddToMultimap() { 110 int oldSize = getNumElements(); 111 112 Collection<V> result = multimap().get(k0()); 113 assertTrue(result.remove(v0())); 114 115 assertFalse(multimap().containsKey(k0())); 116 assertFalse(multimap().containsEntry(k0(), v0())); 117 assertEmpty(result); 118 119 assertTrue(result.add(v1())); 120 assertTrue(result.add(v2())); 121 122 assertContentsAnyOrder(result, v1(), v2()); 123 assertContentsAnyOrder(multimap().get(k0()), v1(), v2()); 124 assertTrue(multimap().containsKey(k0())); 125 assertFalse(multimap().containsEntry(k0(), v0())); 126 assertTrue(multimap().containsEntry(k0(), v2())); 127 assertEquals(oldSize + 1, multimap().size()); 128 } 129 130 @MapFeature.Require(ALLOWS_NULL_KEYS) 131 @CollectionSize.Require(absent = ZERO) 132 public void testGetNullPresent() { 133 initMultimapWithNullKey(); 134 assertContains(multimap().get(null), getValueForNullKey()); 135 } 136 137 @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES) 138 public void testGetNullAbsent() { 139 assertEmpty(multimap().get(null)); 140 } 141 142 @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES) 143 public void testGetNullForbidden() { 144 try { 145 multimap().get(null); 146 fail("Expected NullPointerException"); 147 } catch (NullPointerException expected) { 148 // success 149 } 150 } 151 152 @MapFeature.Require(ALLOWS_NULL_VALUES) 153 @CollectionSize.Require(absent = ZERO) 154 public void testGetWithNullValue() { 155 initMultimapWithNullValue(); 156 assertContains(multimap().get(getKeyForNullValue()), null); 157 } 158 }