Snippet Preview
Snippet HTML Code
1
/*
2
* Copyright (C) 2010 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.testing;
18
19
import com.google.common.annotations.GwtIncompatible;
20
import com.google.common.collect.ImmutableSortedMap;
21
import com.google.common.collect.Lists;
22
import com.google.common.testing.SerializableTester;
23
24
import junit.framework.Test;
25
import junit.framework.TestCase;
26
import junit.framework.TestSuite;
27
28
import java.util.Map;
29
import java.util.SortedMap;
35
36
public class SafeTreeMapTest extends TestCase {
37
public static Test suite() {
38
TestSuite suite = new TestSuite();
39
suite.addTestSuite(SafeTreeMapTest.class);
40
return suite;
41
}
42
43
@GwtIncompatible("SerializableTester")
44
public void testViewSerialization() {
45
Map<String, Integer> map =
46
ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
47
SerializableTester.reserializeAndAssert(map.entrySet());
48
SerializableTester.reserializeAndAssert(map.keySet());
49
assertEquals(Lists.newArrayList(map.values()),
50
Lists.newArrayList(SerializableTester.reserialize(map.values())));
51
52
53
54
public static class ReserializedMapTests
55
extends SortedMapInterfaceTest<String, Integer> {
56
public ReserializedMapTests() {
57
super(false, true, true, true, true);
58
59
60
@Override protected SortedMap<String, Integer> makePopulatedMap() {
61
SortedMap<String, Integer> map = new SafeTreeMap<String, Integer>();
62
map.put("one", 1);
63
map.put("two", 2);
64
map.put("three", 3);
65
return SerializableTester.reserialize(map);
66
67
68
@Override protected SortedMap<String, Integer> makeEmptyMap()
69
throws UnsupportedOperationException {
70
71
72
73
74
@Override protected String getKeyNotInPopulatedMap() {
75
return "minus one";
76
77
78
@Override protected Integer getValueNotInPopulatedMap() {
79
return -1;
80
81
82