1 /* 2 * Copyright (C) 2009 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 junit.framework.TestCase; 21 22 /** 23 * Tests {@link ImmutableTable} 24 * 25 * @author Gregory Kick 26 */ 27 @GwtCompatible 28 public abstract class AbstractImmutableTableTest extends TestCase { 29 getTestInstances()30 abstract Iterable<ImmutableTable<Character, Integer, String>> getTestInstances(); 31 testClear()32 public final void testClear() { 33 for (Table<Character, Integer, String> testInstance : getTestInstances()) { 34 try { 35 testInstance.clear(); 36 fail(); 37 } catch (UnsupportedOperationException e) { 38 // success 39 } 40 } 41 } 42 testPut()43 public final void testPut() { 44 for (Table<Character, Integer, String> testInstance : getTestInstances()) { 45 try { 46 testInstance.put('a', 1, "blah"); 47 fail(); 48 } catch (UnsupportedOperationException e) { 49 // success 50 } 51 } 52 } 53 testPutAll()54 public final void testPutAll() { 55 for (Table<Character, Integer, String> testInstance : getTestInstances()) { 56 try { 57 testInstance.putAll(ImmutableTable.of('a', 1, "blah")); 58 fail(); 59 } catch (UnsupportedOperationException e) { 60 // success 61 } 62 } 63 } 64 testRemove()65 public final void testRemove() { 66 for (Table<Character, Integer, String> testInstance : getTestInstances()) { 67 try { 68 testInstance.remove('a', 1); 69 fail(); 70 } catch (UnsupportedOperationException e) { 71 // success 72 } 73 } 74 } 75 testConsistentToString()76 public final void testConsistentToString() { 77 for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) { 78 assertEquals(testInstance.rowMap().toString(), testInstance.toString()); 79 } 80 } 81 testConsistentHashCode()82 public final void testConsistentHashCode() { 83 for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) { 84 assertEquals(testInstance.cellSet().hashCode(), testInstance.hashCode()); 85 } 86 } 87 } 88