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