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