1 /* 2 * Copyright (C) 2008 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; 18 19 import com.google.common.annotations.GwtCompatible; 20 import com.google.common.base.Joiner; 21 import com.google.common.collect.testing.MapInterfaceTest; 22 import java.util.Map; 23 import java.util.Map.Entry; 24 25 @GwtCompatible 26 abstract class AbstractImmutableBiMapMapInterfaceTest<K, V> extends MapInterfaceTest<K, V> { AbstractImmutableBiMapMapInterfaceTest()27 AbstractImmutableBiMapMapInterfaceTest() { 28 super(false, false, false, false, false); 29 } 30 31 @Override makeEmptyMap()32 protected Map<K, V> makeEmptyMap() { 33 throw new UnsupportedOperationException(); 34 } 35 36 private static final Joiner JOINER = Joiner.on(", "); 37 38 @Override assertMoreInvariants(Map<K, V> map)39 protected final void assertMoreInvariants(Map<K, V> map) { 40 BiMap<K, V> bimap = (BiMap<K, V>) map; 41 42 for (Entry<K, V> entry : map.entrySet()) { 43 assertEquals(entry.getKey() + "=" + entry.getValue(), entry.toString()); 44 assertEquals(entry.getKey(), bimap.inverse().get(entry.getValue())); 45 } 46 47 assertEquals("{" + JOINER.join(map.entrySet()) + "}", map.toString()); 48 assertEquals("[" + JOINER.join(map.entrySet()) + "]", map.entrySet().toString()); 49 assertEquals("[" + JOINER.join(map.keySet()) + "]", map.keySet().toString()); 50 assertEquals("[" + JOINER.join(map.values()) + "]", map.values().toString()); 51 52 assertEquals(Sets.newHashSet(map.entrySet()), map.entrySet()); 53 assertEquals(Sets.newHashSet(map.keySet()), map.keySet()); 54 } 55 } 56