• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 com.google.common.annotations.GwtCompatible;
20 import com.google.common.collect.testing.MapInterfaceTest;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.Map;
24 
25 /**
26  * Test {@code TreeMultimap.asMap().subMap()} with {@link MapInterfaceTest}.
27  *
28  * @author Jared Levy
29  */
30 @GwtCompatible
31 public class SubMapMultimapAsMapImplementsMapTest extends AbstractMultimapAsMapImplementsMapTest {
32 
SubMapMultimapAsMapImplementsMapTest()33   public SubMapMultimapAsMapImplementsMapTest() {
34     super(true, true, true);
35   }
36 
createMultimap()37   private TreeMultimap<String, Integer> createMultimap() {
38     TreeMultimap<String, Integer> multimap =
39         TreeMultimap.create(
40             Ordering.<String>natural().nullsFirst(), Ordering.<Integer>natural().nullsFirst());
41     multimap.put("a", -1);
42     multimap.put("a", -3);
43     multimap.put("z", -2);
44     return multimap;
45   }
46 
47   @Override
makeEmptyMap()48   protected Map<String, Collection<Integer>> makeEmptyMap() {
49     return createMultimap().asMap().subMap("e", "p");
50   }
51 
52   @Override
makePopulatedMap()53   protected Map<String, Collection<Integer>> makePopulatedMap() {
54     TreeMultimap<String, Integer> multimap = createMultimap();
55     multimap.put("f", 1);
56     multimap.put("f", 2);
57     multimap.put("g", 3);
58     multimap.put("h", 4);
59     return multimap.asMap().subMap("e", "p");
60   }
61 
62   @Override
getKeyNotInPopulatedMap()63   protected String getKeyNotInPopulatedMap() {
64     return "a";
65   }
66 
67   @Override
getValueNotInPopulatedMap()68   protected Collection<Integer> getValueNotInPopulatedMap() {
69     return Collections.singleton(-2);
70   }
71 
72   @Override
testEntrySetRemoveAllNullFromEmpty()73   public void testEntrySetRemoveAllNullFromEmpty() {
74     try {
75       super.testEntrySetRemoveAllNullFromEmpty();
76     } catch (RuntimeException tolerated) {
77       // GWT's TreeMap.entrySet().removeAll(null) doesn't throws NPE.
78     }
79   }
80 
81   @Override
testEntrySetRetainAllNullFromEmpty()82   public void testEntrySetRetainAllNullFromEmpty() {
83     try {
84       super.testEntrySetRetainAllNullFromEmpty();
85     } catch (RuntimeException tolerated) {
86       // GWT's TreeMap.entrySet().retainAll(null) doesn't throws NPE.
87     }
88   }
89 
90   @Override
testKeySetRemoveAllNullFromEmpty()91   public void testKeySetRemoveAllNullFromEmpty() {
92     try {
93       super.testKeySetRemoveAllNullFromEmpty();
94     } catch (RuntimeException tolerated) {
95       // GWT's TreeMap.keySet().removeAll(null) doesn't throws NPE.
96     }
97   }
98 
99   @Override
testKeySetRetainAllNullFromEmpty()100   public void testKeySetRetainAllNullFromEmpty() {
101     try {
102       super.testKeySetRetainAllNullFromEmpty();
103     } catch (RuntimeException tolerated) {
104       // GWT's TreeMap.keySet().retainAll(null) doesn't throws NPE.
105     }
106   }
107 
108   @Override
testValuesRemoveAllNullFromEmpty()109   public void testValuesRemoveAllNullFromEmpty() {
110     try {
111       super.testValuesRemoveAllNullFromEmpty();
112     } catch (RuntimeException tolerated) {
113       // GWT's TreeMap.values().removeAll(null) doesn't throws NPE.
114     }
115   }
116 
117   @Override
testValuesRetainAllNullFromEmpty()118   public void testValuesRetainAllNullFromEmpty() {
119     try {
120       super.testValuesRemoveAllNullFromEmpty();
121     } catch (RuntimeException tolerated) {
122       // GWT's TreeMap.values().retainAll(null) doesn't throws NPE.
123     }
124   }
125 }
126