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.Lists; 025import com.google.common.collect.Multimap; 026import com.google.common.collect.testing.features.CollectionFeature; 027import com.google.common.collect.testing.features.CollectionSize; 028import java.util.Iterator; 029import java.util.List; 030import java.util.Map.Entry; 031import org.junit.Ignore; 032 033/** 034 * Tester for {@code Multimap.values}. 035 * 036 * @author Louis Wasserman 037 */ 038@GwtCompatible 039@Ignore("test runners must not instantiate and run this directly, only via suites we build") 040// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 041@SuppressWarnings("JUnit4ClassUsedInJUnit3") 042public class MultimapValuesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 043 public void testValues() { 044 List<V> expected = Lists.newArrayList(); 045 for (Entry<K, V> entry : getSampleElements()) { 046 expected.add(entry.getValue()); 047 } 048 assertEqualIgnoringOrder(expected, multimap().values()); 049 } 050 051 @CollectionFeature.Require(KNOWN_ORDER) 052 public void testValuesInOrder() { 053 List<V> expected = Lists.newArrayList(); 054 for (Entry<K, V> entry : getOrderedElements()) { 055 expected.add(entry.getValue()); 056 } 057 assertEqualInOrder(expected, multimap().values()); 058 } 059 060 @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) 061 @CollectionSize.Require(ONE) 062 public void testValuesIteratorRemove() { 063 Iterator<V> valuesItr = multimap().values().iterator(); 064 valuesItr.next(); 065 valuesItr.remove(); 066 assertTrue(multimap().isEmpty()); 067 } 068}