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.base.Function;
23
24
25
26
27
28
29 @GwtCompatible(emulated = true)
30 public class TablesTransformValuesTest extends AbstractTableTest {
31
32 private static final Function<String, Character> FIRST_CHARACTER
33 = new Function<String, Character>() {
34 @Override public Character apply(String input) {
35 return input == null ? null : input.charAt(0);
36 }
37 };
38
39 @Override protected Table<String, Integer, Character> create(
40 Object... data) {
41 Table<String, Integer, String> table = HashBasedTable.create();
42 checkArgument(data.length % 3 == 0);
43 for (int i = 0; i < data.length; i += 3) {
44 String value =
45 (data[i + 2] == null) ? null : (data[i + 2] + "transformed");
46 table.put((String) data[i], (Integer) data[i + 1], value);
47 }
48 return Tables.transformValues(table, FIRST_CHARACTER);
49 }
50
51
52
53
54 @Override public void testPut() {
55 try {
56 table.put("foo", 1, 'a');
57 fail("Expected UnsupportedOperationException");
58 } catch (UnsupportedOperationException expected) {}
59 assertSize(0);
60 }
61
62 @Override public void testPutAllTable() {
63 table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
64 Table<String, Integer, Character> other = HashBasedTable.create();
65 other.put("foo", 1, 'd');
66 other.put("bar", 2, 'e');
67 other.put("cat", 2, 'f');
68 try {
69 table.putAll(other);
70 fail("Expected UnsupportedOperationException");
71 } catch (UnsupportedOperationException expected) {}
72 assertEquals((Character) 'a', table.get("foo", 1));
73 assertEquals((Character) 'b', table.get("bar", 1));
74 assertEquals((Character) 'c', table.get("foo", 3));
75 assertSize(3);
76 }
77
78 @Override public void testPutNull() {}
79 @Override public void testPutNullReplace() {}
80 @Override public void testRowClearAndPut() {}
81 }
82