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 com.google.common.collect.testing.MinimalSet; 23 import java.util.Map; 24 import java.util.Map.Entry; 25 26 @GwtCompatible 27 abstract class AbstractImmutableMapMapInterfaceTest<K, V> extends MapInterfaceTest<K, V> { AbstractImmutableMapMapInterfaceTest()28 AbstractImmutableMapMapInterfaceTest() { 29 super(false, false, false, false, false); 30 } 31 32 @Override makeEmptyMap()33 protected Map<K, V> makeEmptyMap() { 34 throw new UnsupportedOperationException(); 35 } 36 37 private static final Joiner JOINER = Joiner.on(", "); 38 39 @Override assertMoreInvariants(Map<K, V> map)40 protected final void assertMoreInvariants(Map<K, V> map) { 41 // TODO: can these be moved to MapInterfaceTest? 42 for (Entry<K, V> entry : map.entrySet()) { 43 assertEquals(entry.getKey() + "=" + entry.getValue(), entry.toString()); 44 } 45 46 assertEquals("{" + JOINER.join(map.entrySet()) + "}", map.toString()); 47 assertEquals("[" + JOINER.join(map.entrySet()) + "]", map.entrySet().toString()); 48 assertEquals("[" + JOINER.join(map.keySet()) + "]", map.keySet().toString()); 49 assertEquals("[" + JOINER.join(map.values()) + "]", map.values().toString()); 50 51 assertEquals(MinimalSet.from(map.entrySet()), map.entrySet()); 52 assertEquals(Sets.newHashSet(map.keySet()), map.keySet()); 53 } 54 } 55