• 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<>('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")), testTable.rowMap());
68   }
69 
testEqualsObject()70   public void testEqualsObject() {
71     new EqualsTester()
72         .addEqualityGroup(testTable, HashBasedTable.create(testTable))
73         .addEqualityGroup(ImmutableTable.of(), HashBasedTable.create())
74         .addEqualityGroup(HashBasedTable.create(ImmutableTable.of('A', 2, "")))
75         .testEquals();
76   }
77 
78   @GwtIncompatible // ArrayTable
testEqualsObjectNullValues()79   public void testEqualsObjectNullValues() {
80     new EqualsTester()
81         .addEqualityGroup(testTable)
82         .addEqualityGroup(ArrayTable.create(ImmutableSet.of('A'), ImmutableSet.of(1)))
83         .testEquals();
84   }
85 
testToString()86   public void testToString() {
87     assertEquals("{a={1=blah}}", testTable.toString());
88   }
89 
testContains()90   public void testContains() {
91     assertTrue(testTable.contains('a', 1));
92     assertFalse(testTable.contains('a', 2));
93     assertFalse(testTable.contains('A', 1));
94     assertFalse(testTable.contains('A', 2));
95   }
96 
testContainsColumn()97   public void testContainsColumn() {
98     assertTrue(testTable.containsColumn(1));
99     assertFalse(testTable.containsColumn(2));
100   }
101 
testContainsRow()102   public void testContainsRow() {
103     assertTrue(testTable.containsRow('a'));
104     assertFalse(testTable.containsRow('A'));
105   }
106 
testContainsValue()107   public void testContainsValue() {
108     assertTrue(testTable.containsValue("blah"));
109     assertFalse(testTable.containsValue(""));
110   }
111 
testGet()112   public void testGet() {
113     assertEquals("blah", testTable.get('a', 1));
114     assertNull(testTable.get('a', 2));
115     assertNull(testTable.get('A', 1));
116     assertNull(testTable.get('A', 2));
117   }
118 
testIsEmpty()119   public void testIsEmpty() {
120     assertFalse(testTable.isEmpty());
121   }
122 
testSize()123   public void testSize() {
124     assertEquals(1, testTable.size());
125   }
126 
testValues()127   public void testValues() {
128     assertThat(testTable.values()).contains("blah");
129   }
130 
131   @Override
getTestInstances()132   Iterable<ImmutableTable<Character, Integer, String>> getTestInstances() {
133     return ImmutableSet.of(testTable);
134   }
135 }
136