• 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 public Character apply(String input) {
36         return input == null ? null : input.charAt(0);
37       }
38   };
39 
create( Object... data)40   @Override protected Table<String, Integer, Character> create(
41       Object... data) {
42     Table<String, Integer, String> table = HashBasedTable.create();
43     checkArgument(data.length % 3 == 0);
44     for (int i = 0; i < data.length; i += 3) {
45       String value =
46           (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")
testNullPointerInstance()54   @Override public void testNullPointerInstance() {}
55 
56   // put() and putAll() aren't supported.
testPut()57   @Override public void testPut() {
58     try {
59       table.put("foo", 1, 'a');
60       fail("Expected UnsupportedOperationException");
61     } catch (UnsupportedOperationException expected) {}
62     assertSize(0);
63   }
64 
testPutAllTable()65   @Override public void testPutAllTable() {
66     table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
67     Table<String, Integer, Character> other = HashBasedTable.create();
68     other.put("foo", 1, 'd');
69     other.put("bar", 2, 'e');
70     other.put("cat", 2, 'f');
71     try {
72       table.putAll(other);
73       fail("Expected UnsupportedOperationException");
74     } catch (UnsupportedOperationException expected) {}
75     assertEquals((Character) 'a', table.get("foo", 1));
76     assertEquals((Character) 'b', table.get("bar", 1));
77     assertEquals((Character) 'c', table.get("foo", 3));
78     assertSize(3);
79   }
80 
testPutNull()81   @Override public void testPutNull() {}
testPutNullReplace()82   @Override public void testPutNullReplace() {}
testRowClearAndPut()83   @Override public void testRowClearAndPut() {}
84 }
85