/
TablesTransformValuesTest.java
98 lines (86 loc) · 3.1 KB
/
TablesTransformValuesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Test cases for {@link Tables#transformValues}.
*
* @author Jared Levy
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public class TablesTransformValuesTest extends AbstractTableTest<Character> {
private static final Function<@Nullable String, @Nullable Character> FIRST_CHARACTER =
new Function<@Nullable String, @Nullable Character>() {
@Override
public @Nullable Character apply(@Nullable String input) {
return input == null ? null : input.charAt(0);
}
};
@Override
protected Table<String, Integer, Character> create(@Nullable Object... data) {
Table<String, Integer, String> table = HashBasedTable.create();
checkArgument(data.length % 3 == 0);
for (int i = 0; i < data.length; i += 3) {
String value = (data[i + 2] == null) ? null : (data[i + 2] + "transformed");
table.put((String) data[i], (Integer) data[i + 1], value);
}
return Tables.transformValues(table, FIRST_CHARACTER);
}
// Null support depends on the underlying table and function.
@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@Override
public void testNullPointerInstance() {}
// put() and putAll() aren't supported.
@Override
public void testPut() {
try {
table.put("foo", 1, 'a');
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
assertSize(0);
}
@Override
public void testPutAllTable() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
other.put("cat", 2, 'f');
try {
table.putAll(other);
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
assertEquals((Character) 'a', table.get("foo", 1));
assertEquals((Character) 'b', table.get("bar", 1));
assertEquals((Character) 'c', table.get("foo", 3));
assertSize(3);
}
@Override
public void testPutNull() {}
@Override
public void testPutNullReplace() {}
@Override
public void testRowClearAndPut() {}
}