• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.google.common.truth.Truth.assertThat;
20 
21 import com.google.common.annotations.GwtCompatible;
22 import com.google.common.annotations.GwtIncompatible;
23 import com.google.common.base.Objects;
24 import com.google.common.testing.EqualsTester;
25 
26 /**
27  * Tests {@link SingletonImmutableTable}.
28  *
29  * @author Gregory Kick
30  */
31 @GwtCompatible(emulated = true)
32 public class SingletonImmutableTableTest extends AbstractImmutableTableTest {
33   private final ImmutableTable<Character, Integer, String> testTable =
34       new SingletonImmutableTable<Character, Integer, String>('a', 1, "blah");
35 
testHashCode()36   public void testHashCode() {
37     assertEquals(Objects.hashCode('a', 1, "blah"), testTable.hashCode());
38   }
39 
testCellSet()40   public void testCellSet() {
41     assertEquals(ImmutableSet.of(Tables.immutableCell('a', 1, "blah")), testTable.cellSet());
42   }
43 
testColumn()44   public void testColumn() {
45     assertEquals(ImmutableMap.of(), testTable.column(0));
46     assertEquals(ImmutableMap.of('a', "blah"), testTable.column(1));
47   }
48 
testColumnKeySet()49   public void testColumnKeySet() {
50     assertEquals(ImmutableSet.of(1), testTable.columnKeySet());
51   }
52 
testColumnMap()53   public void testColumnMap() {
54     assertEquals(ImmutableMap.of(1, ImmutableMap.of('a', "blah")), testTable.columnMap());
55   }
56 
testRow()57   public void testRow() {
58     assertEquals(ImmutableMap.of(), testTable.row('A'));
59     assertEquals(ImmutableMap.of(1, "blah"), testTable.row('a'));
60   }
61 
testRowKeySet()62   public void testRowKeySet() {
63     assertEquals(ImmutableSet.of('a'), testTable.rowKeySet());
64   }
65 
testRowMap()66   public void testRowMap() {
67     assertEquals(ImmutableMap.of('a', ImmutableMap.of(1, "blah")),
68         testTable.rowMap());
69   }
70 
testEqualsObject()71   public void testEqualsObject() {
72     new EqualsTester()
73         .addEqualityGroup(testTable, HashBasedTable.create(testTable))
74         .addEqualityGroup(ImmutableTable.of(), HashBasedTable.create())
75         .addEqualityGroup(HashBasedTable.create(ImmutableTable.of('A', 2, "")))
76         .testEquals();
77   }
78 
79   @GwtIncompatible("ArrayTable")
testEqualsObjectNullValues()80   public void testEqualsObjectNullValues() {
81     new EqualsTester()
82         .addEqualityGroup(testTable)
83         .addEqualityGroup(ArrayTable.create(ImmutableSet.of('A'), ImmutableSet.of(1)))
84         .testEquals();
85   }
86 
testToString()87   public void testToString() {
88     assertEquals("{a={1=blah}}", testTable.toString());
89   }
90 
testContains()91   public void testContains() {
92     assertTrue(testTable.contains('a', 1));
93     assertFalse(testTable.contains('a', 2));
94     assertFalse(testTable.contains('A', 1));
95     assertFalse(testTable.contains('A', 2));
96   }
97 
testContainsColumn()98   public void testContainsColumn() {
99     assertTrue(testTable.containsColumn(1));
100     assertFalse(testTable.containsColumn(2));
101   }
102 
testContainsRow()103   public void testContainsRow() {
104     assertTrue(testTable.containsRow('a'));
105     assertFalse(testTable.containsRow('A'));
106   }
107 
testContainsValue()108   public void testContainsValue() {
109     assertTrue(testTable.containsValue("blah"));
110     assertFalse(testTable.containsValue(""));
111   }
112 
testGet()113   public void testGet() {
114     assertEquals("blah", testTable.get('a', 1));
115     assertNull(testTable.get('a', 2));
116     assertNull(testTable.get('A', 1));
117     assertNull(testTable.get('A', 2));
118   }
119 
testIsEmpty()120   public void testIsEmpty() {
121     assertFalse(testTable.isEmpty());
122   }
123 
testSize()124   public void testSize() {
125     assertEquals(1, testTable.size());
126   }
127 
testValues()128   public void testValues() {
129     assertThat(testTable.values()).has().item("blah");
130   }
131 
getTestInstances()132   @Override Iterable<ImmutableTable<Character, Integer, String>> getTestInstances() {
133     return ImmutableSet.of(testTable);
134   }
135 }
136