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 17package com.google.common.collect; 18 19import com.google.common.annotations.GwtIncompatible; 20import com.google.common.base.Predicate; 21 22import java.util.Collection; 23import java.util.Map; 24import java.util.Map.Entry; 25 26/** 27 * Tests for Multimaps.filterEntries().asMap(). 28 * 29 * @author Jared Levy 30 */ 31@GwtIncompatible(value = "untested") 32public class MultimapsFilterEntriesAsMapTest 33 extends AbstractMultimapAsMapImplementsMapTest { 34 private static final Predicate<Map.Entry<String, Integer>> PREDICATE 35 = new Predicate<Map.Entry<String, Integer>>() { 36 @Override public boolean apply(Entry<String, Integer> entry) { 37 return !"badkey".equals(entry.getKey()) && 55556 != entry.getValue(); 38 } 39 }; 40 41 public MultimapsFilterEntriesAsMapTest() { 42 super(true, true, false); 43 } 44 45 private Multimap<String, Integer> createMultimap() { 46 Multimap<String, Integer> unfiltered = HashMultimap.create(); 47 unfiltered.put("zero", 55556); 48 unfiltered.put("one", 55556); 49 unfiltered.put("badkey", 1); 50 return Multimaps.filterEntries(unfiltered, PREDICATE); 51 } 52 53 @Override protected Map<String, Collection<Integer>> makeEmptyMap() { 54 Multimap<String, Integer> multimap = createMultimap(); 55 return multimap.asMap(); 56 } 57 58 @Override protected Map<String, Collection<Integer>> makePopulatedMap() { 59 Multimap<String, Integer> multimap = createMultimap(); 60 populate(multimap); 61 return multimap.asMap(); 62 } 63} 64