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