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