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.annotations.GwtIncompatible; 21 import com.google.common.collect.Table.Cell; 22 import com.google.common.testing.EqualsTester; 23 import com.google.common.testing.SerializableTester; 24 25 import junit.framework.TestCase; 26 27 /** 28 * Tests for {@link Tables}. 29 * 30 * @author Jared Levy 31 */ 32 @GwtCompatible(emulated = true) 33 public class TablesTest extends TestCase { 34 35 @GwtIncompatible("SerializableTester") 36 public void testImmutableEntrySerialization() { 37 Cell<String, Integer, Character> entry 38 = Tables.immutableCell("foo", 1, 'a'); 39 SerializableTester.reserializeAndAssert(entry); 40 } 41 42 public void testImmutableEntryToString() { 43 Cell<String, Integer, Character> entry 44 = Tables.immutableCell("foo", 1, 'a'); 45 assertEquals("(foo,1)=a", entry.toString()); 46 47 Cell<String, Integer, Character> nullEntry 48 = Tables.immutableCell(null, null, null); 49 assertEquals("(null,null)=null", nullEntry.toString()); 50 } 51 52 public void testEntryEquals() { 53 Cell<String, Integer, Character> entry 54 = Tables.immutableCell("foo", 1, 'a'); 55 56 new EqualsTester() 57 .addEqualityGroup(entry, Tables.immutableCell("foo", 1, 'a')) 58 .addEqualityGroup(Tables.immutableCell("bar", 1, 'a')) 59 .addEqualityGroup(Tables.immutableCell("foo", 2, 'a')) 60 .addEqualityGroup(Tables.immutableCell("foo", 1, 'b')) 61 .addEqualityGroup(Tables.immutableCell(null, null, null)) 62 .testEquals(); 63 } 64 65 public void testEntryEqualsNull() { 66 Cell<String, Integer, Character> entry 67 = Tables.immutableCell(null, null, null); 68 69 new EqualsTester() 70 .addEqualityGroup(entry, Tables.immutableCell(null, null, null)) 71 .addEqualityGroup(Tables.immutableCell("bar", null, null)) 72 .addEqualityGroup(Tables.immutableCell(null, 2, null)) 73 .addEqualityGroup(Tables.immutableCell(null, null, 'b')) 74 .addEqualityGroup(Tables.immutableCell("foo", 1, 'a')) 75 .testEquals(); 76 } 77 } 78