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