Coverage Summary for Class: SetMultimapAsMapTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| SetMultimapAsMapTester | 0% (0/1) | 0% (0/7) | 0% (0/35) |
1 /* 2 * Copyright (C) 2013 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.collect.testing.google; 16 17 import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 18 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 19 20 import com.google.common.annotations.GwtCompatible; 21 import com.google.common.collect.Maps; 22 import com.google.common.collect.SetMultimap; 23 import com.google.common.collect.Sets; 24 import com.google.common.collect.testing.Helpers; 25 import com.google.common.collect.testing.features.CollectionSize; 26 import com.google.common.collect.testing.features.MapFeature; 27 import com.google.common.testing.EqualsTester; 28 import java.util.ArrayList; 29 import java.util.Collection; 30 import java.util.Collections; 31 import java.util.List; 32 import java.util.Map; 33 import java.util.Map.Entry; 34 import java.util.Set; 35 import org.junit.Ignore; 36 37 /** 38 * Testers for {@link SetMultimap#asMap}. 39 * 40 * @author Louis Wasserman 41 * @param <K> The key type of the tested multimap. 42 * @param <V> The value type of the tested multimap. 43 */ 44 @GwtCompatible 45 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 46 public class SetMultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, SetMultimap<K, V>> { 47 public void testAsMapValuesImplementSet() { 48 for (Collection<V> valueCollection : multimap().asMap().values()) { 49 assertTrue(valueCollection instanceof Set); 50 } 51 } 52 53 public void testAsMapGetImplementsSet() { 54 for (K key : multimap().keySet()) { 55 assertTrue(multimap().asMap().get(key) instanceof Set); 56 } 57 } 58 59 @MapFeature.Require(SUPPORTS_REMOVE) 60 public void testAsMapRemoveImplementsSet() { 61 List<K> keys = new ArrayList<K>(multimap().keySet()); 62 for (K key : keys) { 63 resetCollection(); 64 assertTrue(multimap().asMap().remove(key) instanceof Set); 65 } 66 } 67 68 @CollectionSize.Require(SEVERAL) 69 public void testEquals() { 70 resetContainer( 71 Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k1(), v0()), Helpers.mapEntry(k0(), v3())); 72 Map<K, Collection<V>> expected = Maps.newHashMap(); 73 expected.put(k0(), Sets.newHashSet(v0(), v3())); 74 expected.put(k1(), Sets.newHashSet(v0())); 75 new EqualsTester().addEqualityGroup(expected, multimap().asMap()).testEquals(); 76 } 77 78 @CollectionSize.Require(SEVERAL) 79 public void testEntrySetEquals() { 80 resetContainer( 81 Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k1(), v0()), Helpers.mapEntry(k0(), v3())); 82 Set<Entry<K, Collection<V>>> expected = Sets.newHashSet(); 83 expected.add(Helpers.mapEntry(k0(), (Collection<V>) Sets.newHashSet(v0(), v3()))); 84 expected.add(Helpers.mapEntry(k1(), (Collection<V>) Sets.newHashSet(v0()))); 85 new EqualsTester().addEqualityGroup(expected, multimap().asMap().entrySet()).testEquals(); 86 } 87 88 @CollectionSize.Require(SEVERAL) 89 @MapFeature.Require(SUPPORTS_REMOVE) 90 public void testValuesRemove() { 91 resetContainer( 92 Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k1(), v0()), Helpers.mapEntry(k0(), v3())); 93 assertTrue(multimap().asMap().values().remove(Collections.singleton(v0()))); 94 assertEquals(2, multimap().size()); 95 assertEquals(Collections.singletonMap(k0(), Sets.newHashSet(v0(), v3())), multimap().asMap()); 96 } 97 }