Coverage Summary for Class: MultimapReplaceValuesTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| MultimapReplaceValuesTester | 0% (0/1) | 0% (0/10) | 0% (0/57) |
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.assertContentsAnyOrder; 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 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 25 26 import com.google.common.annotations.GwtCompatible; 27 import com.google.common.collect.Multimap; 28 import com.google.common.collect.testing.Helpers; 29 import com.google.common.collect.testing.features.CollectionSize; 30 import com.google.common.collect.testing.features.MapFeature; 31 import java.util.ArrayList; 32 import java.util.Arrays; 33 import java.util.Collection; 34 import java.util.Collections; 35 import java.util.List; 36 import org.junit.Ignore; 37 38 /** 39 * Tests for {@link Multimap#replaceValues(Object, Iterable)}. 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 MultimapReplaceValuesTester<K, V> 46 extends AbstractMultimapTester<K, V, Multimap<K, V>> { 47 48 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE, ALLOWS_NULL_VALUES}) 49 public void testReplaceValuesWithNullValue() { 50 @SuppressWarnings("unchecked") 51 List<V> values = Arrays.asList(v0(), null, v3()); 52 multimap().replaceValues(k0(), values); 53 assertGet(k0(), values); 54 } 55 56 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE, ALLOWS_NULL_KEYS}) 57 public void testReplaceValuesWithNullKey() { 58 @SuppressWarnings("unchecked") 59 List<V> values = Arrays.asList(v0(), v2(), v3()); 60 multimap().replaceValues(null, values); 61 assertGet(null, values); 62 } 63 64 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE}) 65 public void testReplaceEmptyValues() { 66 int size = multimap().size(); 67 @SuppressWarnings("unchecked") 68 List<V> values = Arrays.asList(v0(), v2(), v3()); 69 multimap().replaceValues(k3(), values); 70 assertGet(k3(), values); 71 assertEquals(size + values.size(), multimap().size()); 72 } 73 74 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE}) 75 public void testReplaceValuesWithEmpty() { 76 int size = multimap().size(); 77 List<V> oldValues = new ArrayList<>(multimap().get(k0())); 78 @SuppressWarnings("unchecked") 79 List<V> values = Collections.emptyList(); 80 assertEquals(oldValues, new ArrayList<V>(multimap().replaceValues(k0(), values))); 81 assertGet(k0()); 82 assertEquals(size - oldValues.size(), multimap().size()); 83 } 84 85 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE}) 86 public void testReplaceValuesWithDuplicates() { 87 int size = multimap().size(); 88 List<V> oldValues = new ArrayList<>(multimap().get(k0())); 89 List<V> values = Arrays.asList(v0(), v3(), v0()); 90 assertEquals(oldValues, new ArrayList<V>(multimap().replaceValues(k0(), values))); 91 assertEquals(size - oldValues.size() + multimap().get(k0()).size(), multimap().size()); 92 assertTrue(multimap().get(k0()).containsAll(values)); 93 } 94 95 @CollectionSize.Require(absent = ZERO) 96 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE}) 97 public void testReplaceNonEmptyValues() { 98 List<K> keys = Helpers.copyToList(multimap().keySet()); 99 @SuppressWarnings("unchecked") 100 List<V> values = Arrays.asList(v0(), v2(), v3()); 101 102 for (K k : keys) { 103 resetContainer(); 104 105 int size = multimap().size(); 106 Collection<V> oldKeyValues = Helpers.copyToList(multimap().get(k)); 107 multimap().replaceValues(k, values); 108 assertGet(k, values); 109 assertEquals(size + values.size() - oldKeyValues.size(), multimap().size()); 110 } 111 } 112 113 @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE}) 114 public void testReplaceValuesPropagatesToGet() { 115 Collection<V> getCollection = multimap().get(k0()); 116 @SuppressWarnings("unchecked") 117 List<V> values = Arrays.asList(v0(), v2(), v3()); 118 multimap().replaceValues(k0(), values); 119 assertContentsAnyOrder(getCollection, v0(), v2(), v3()); 120 } 121 122 @MapFeature.Require(absent = SUPPORTS_REMOVE) 123 @CollectionSize.Require(absent = ZERO) 124 public void testReplaceValuesRemoveNotSupported() { 125 List<V> values = Collections.singletonList(v3()); 126 try { 127 multimap().replaceValues(k0(), values); 128 fail("Expected UnsupportedOperationException"); 129 } catch (UnsupportedOperationException expected) { 130 // success 131 } 132 } 133 134 @MapFeature.Require(absent = SUPPORTS_PUT) 135 public void testReplaceValuesPutNotSupported() { 136 List<V> values = Collections.singletonList(v3()); 137 try { 138 multimap().replaceValues(k0(), values); 139 fail("Expected UnsupportedOperationException"); 140 } catch (UnsupportedOperationException expected) { 141 // success 142 } 143 } 144 }