Coverage Summary for Class: AbstractBiMapTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| AbstractBiMapTester | 0% (0/1) | 0% (0/5) | 0% (0/32) |
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 com.google.common.annotations.GwtCompatible; 20 import com.google.common.collect.BiMap; 21 import com.google.common.collect.testing.AbstractMapTester; 22 import com.google.common.collect.testing.Helpers; 23 import java.util.ArrayList; 24 import java.util.Collection; 25 import java.util.List; 26 import java.util.Map.Entry; 27 import org.junit.Ignore; 28 29 /** Skeleton for a tester of a {@code BiMap}. */ 30 @GwtCompatible 31 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 32 public abstract class AbstractBiMapTester<K, V> extends AbstractMapTester<K, V> { 33 34 @Override 35 protected BiMap<K, V> getMap() { 36 return (BiMap<K, V>) super.getMap(); 37 } 38 39 static <K, V> Entry<V, K> reverseEntry(Entry<K, V> entry) { 40 return Helpers.mapEntry(entry.getValue(), entry.getKey()); 41 } 42 43 @Override 44 protected void expectContents(Collection<Entry<K, V>> expected) { 45 super.expectContents(expected); 46 List<Entry<V, K>> reversedEntries = new ArrayList<>(); 47 for (Entry<K, V> entry : expected) { 48 reversedEntries.add(reverseEntry(entry)); 49 } 50 Helpers.assertEqualIgnoringOrder(getMap().inverse().entrySet(), reversedEntries); 51 52 for (Entry<K, V> entry : expected) { 53 assertEquals( 54 "Wrong key for value " + entry.getValue(), 55 entry.getKey(), 56 getMap().inverse().get(entry.getValue())); 57 } 58 } 59 60 @Override 61 protected void expectMissing(Entry<K, V>... entries) { 62 super.expectMissing(entries); 63 for (Entry<K, V> entry : entries) { 64 Entry<V, K> reversed = reverseEntry(entry); 65 BiMap<V, K> inv = getMap().inverse(); 66 assertFalse( 67 "Inverse should not contain entry " + reversed, inv.entrySet().contains(reversed)); 68 assertFalse( 69 "Inverse should not contain key " + reversed.getKey(), 70 inv.containsKey(reversed.getKey())); 71 assertFalse( 72 "Inverse should not contain value " + reversed.getValue(), 73 inv.containsValue(reversed.getValue())); 74 /* 75 * TODO(cpovirk): This is a bit stronger than super.expectMissing(), which permits a <key, 76 * someOtherValue> pair. 77 */ 78 assertNull( 79 "Inverse should not return a mapping for key " + reversed.getKey(), 80 inv.get(reversed.getKey())); 81 } 82 } 83 }