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