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