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