Home | History | Annotate | Download | only in collect
      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 
     24 import java.util.Map;
     25 import java.util.TreeMap;
     26 
     27 /**
     28  * Test cases for {@link Tables#newCustomTable}.
     29  *
     30  * @author Jared Levy
     31  */
     32 @GwtCompatible
     33 public 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     assertThat(table.rowKeySet()).has().exactly("foo", "bar").inOrder();
     55   }
     56 
     57   public void testRowOrdering() {
     58     table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
     59     assertThat(table.row("foo").keySet()).has().exactly(2, 3).inOrder();
     60   }
     61 }
     62