1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
27
28
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
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
53 @GwtIncompatible("NullPointerTester")
54 @Override public void testNullPointerInstance() {}
55
56
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
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
81 @Override public void testPutNull() {}
82 @Override public void testPutNullReplace() {}
83 @Override public void testRowClearAndPut() {}
84 }