• 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 static com.google.common.truth.Truth.assertThat;
20 
21 import com.google.common.annotations.GwtCompatible;
22 import com.google.common.base.Supplier;
23 import java.util.Map;
24 import java.util.TreeMap;
25 
26 /**
27  * Test cases for {@link Tables#newCustomTable}.
28  *
29  * @author Jared Levy
30  */
31 @GwtCompatible
32 public class NewCustomTableTest extends AbstractTableTest {
33 
34   @Override
create(Object... data)35   protected Table<String, Integer, Character> create(Object... data) {
36     Supplier<TreeMap<Integer, Character>> factory =
37         new Supplier<TreeMap<Integer, Character>>() {
38           @Override
39           public TreeMap<Integer, Character> get() {
40             return Maps.newTreeMap();
41           }
42         };
43     Map<String, Map<Integer, Character>> backingMap = Maps.newLinkedHashMap();
44     Table<String, Integer, Character> table = Tables.newCustomTable(backingMap, factory);
45     populate(table, data);
46     return table;
47   }
48 
testRowKeySetOrdering()49   public void testRowKeySetOrdering() {
50     table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
51     assertThat(table.rowKeySet()).containsExactly("foo", "bar").inOrder();
52   }
53 
testRowOrdering()54   public void testRowOrdering() {
55     table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
56     assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();
57   }
58 }
59