001/* 002 * Copyright (C) 2013 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.collect.testing.google; 016 017import static com.google.common.collect.testing.Helpers.assertEqualIgnoringOrder; 018import static com.google.common.collect.testing.Helpers.assertEqualInOrder; 019import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; 020import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ITERATOR_REMOVE; 021import static com.google.common.collect.testing.features.CollectionSize.ONE; 022 023import com.google.common.annotations.GwtCompatible; 024import com.google.common.collect.Multimap; 025import com.google.common.collect.testing.features.CollectionFeature; 026import com.google.common.collect.testing.features.CollectionSize; 027import java.util.ArrayList; 028import java.util.Iterator; 029import java.util.List; 030import java.util.Map.Entry; 031 032/** 033 * Tester for {@code Multimap.values}. 034 * 035 * @author Louis Wasserman 036 */ 037@GwtCompatible 038public class MultimapValuesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 039 public void testValues() { 040 List<V> expected = new ArrayList<>(); 041 for (Entry<K, V> entry : getSampleElements()) { 042 expected.add(entry.getValue()); 043 } 044 assertEqualIgnoringOrder(expected, multimap().values()); 045 } 046 047 @CollectionFeature.Require(KNOWN_ORDER) 048 public void testValuesInOrder() { 049 List<V> expected = new ArrayList<>(); 050 for (Entry<K, V> entry : getOrderedElements()) { 051 expected.add(entry.getValue()); 052 } 053 assertEqualInOrder(expected, multimap().values()); 054 } 055 056 @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) 057 @CollectionSize.Require(ONE) 058 public void testValuesIteratorRemove() { 059 Iterator<V> valuesItr = multimap().values().iterator(); 060 valuesItr.next(); 061 valuesItr.remove(); 062 assertTrue(multimap().isEmpty()); 063 } 064}