• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.base.Preconditions.checkArgument;
20 
21 import com.google.common.annotations.GwtCompatible;
22 import com.google.common.annotations.GwtIncompatible;
23 import com.google.common.base.Function;
24 
25 /**
26  * Test cases for {@link Tables#transformValues}.
27  *
28  * @author Jared Levy
29  */
30 @GwtCompatible(emulated = true)
31 public class TablesTransformValuesTest extends AbstractTableTest {
32 
33   private static final Function<String, Character> FIRST_CHARACTER =
34       new Function<String, Character>() {
35         @Override
36         public Character apply(String input) {
37           return input == null ? null : input.charAt(0);
38         }
39       };
40 
41   @Override
create(Object... data)42   protected Table<String, Integer, Character> create(Object... data) {
43     Table<String, Integer, String> table = HashBasedTable.create();
44     checkArgument(data.length % 3 == 0);
45     for (int i = 0; i < data.length; i += 3) {
46       String value = (data[i + 2] == null) ? null : (data[i + 2] + "transformed");
47       table.put((String) data[i], (Integer) data[i + 1], value);
48     }
49     return Tables.transformValues(table, FIRST_CHARACTER);
50   }
51 
52   // Null support depends on the underlying table and function.
53   @GwtIncompatible // NullPointerTester
54   @Override
testNullPointerInstance()55   public void testNullPointerInstance() {}
56 
57   // put() and putAll() aren't supported.
58   @Override
testPut()59   public void testPut() {
60     try {
61       table.put("foo", 1, 'a');
62       fail("Expected UnsupportedOperationException");
63     } catch (UnsupportedOperationException expected) {
64     }
65     assertSize(0);
66   }
67 
68   @Override
testPutAllTable()69   public void testPutAllTable() {
70     table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
71     Table<String, Integer, Character> other = HashBasedTable.create();
72     other.put("foo", 1, 'd');
73     other.put("bar", 2, 'e');
74     other.put("cat", 2, 'f');
75     try {
76       table.putAll(other);
77       fail("Expected UnsupportedOperationException");
78     } catch (UnsupportedOperationException expected) {
79     }
80     assertEquals((Character) 'a', table.get("foo", 1));
81     assertEquals((Character) 'b', table.get("bar", 1));
82     assertEquals((Character) 'c', table.get("foo", 3));
83     assertSize(3);
84   }
85 
86   @Override
testPutNull()87   public void testPutNull() {}
88 
89   @Override
testPutNullReplace()90   public void testPutNullReplace() {}
91 
92   @Override
testRowClearAndPut()93   public void testRowClearAndPut() {}
94 }
95