001/* 002 * Copyright (C) 2012 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.assertContentsInOrder; 018import static com.google.common.collect.testing.Helpers.copyToList; 019import static com.google.common.collect.testing.Helpers.mapEntry; 020import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 021import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; 022 023import com.google.common.annotations.GwtCompatible; 024import com.google.common.collect.ListMultimap; 025import com.google.common.collect.testing.features.CollectionSize; 026import com.google.common.collect.testing.features.MapFeature; 027import java.util.Arrays; 028import java.util.Collection; 029import java.util.List; 030import java.util.Map.Entry; 031import org.junit.Ignore; 032 033/** 034 * Testers for {@link ListMultimap#remove(Object, Object)}. 035 * 036 * @author Louis Wasserman 037 */ 038@GwtCompatible 039@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 040public class ListMultimapRemoveTester<K, V> extends AbstractListMultimapTester<K, V> { 041 @SuppressWarnings("unchecked") 042 @MapFeature.Require(SUPPORTS_REMOVE) 043 @CollectionSize.Require(SEVERAL) 044 public void testMultimapRemoveDeletesFirstOccurrence() { 045 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 046 047 List<V> list = multimap().get(k0()); 048 multimap().remove(k0(), v0()); 049 assertContentsInOrder(list, v1(), v0()); 050 } 051 052 @SuppressWarnings("unchecked") 053 @MapFeature.Require(SUPPORTS_REMOVE) 054 @CollectionSize.Require(SEVERAL) 055 public void testRemoveAtIndexFromGetPropagates() { 056 List<V> values = Arrays.asList(v0(), v1(), v0()); 057 058 for (int i = 0; i < 3; i++) { 059 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 060 List<V> expectedValues = copyToList(values); 061 062 multimap().get(k0()).remove(i); 063 expectedValues.remove(i); 064 065 assertGet(k0(), expectedValues); 066 } 067 } 068 069 @SuppressWarnings("unchecked") 070 @MapFeature.Require(SUPPORTS_REMOVE) 071 @CollectionSize.Require(SEVERAL) 072 public void testRemoveAtIndexFromAsMapPropagates() { 073 List<V> values = Arrays.asList(v0(), v1(), v0()); 074 075 for (int i = 0; i < 3; i++) { 076 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 077 List<V> expectedValues = copyToList(values); 078 079 List<V> asMapValue = (List<V>) multimap().asMap().get(k0()); 080 asMapValue.remove(i); 081 expectedValues.remove(i); 082 083 assertGet(k0(), expectedValues); 084 } 085 } 086 087 @SuppressWarnings("unchecked") 088 @MapFeature.Require(SUPPORTS_REMOVE) 089 @CollectionSize.Require(SEVERAL) 090 public void testRemoveAtIndexFromAsMapEntrySetPropagates() { 091 List<V> values = Arrays.asList(v0(), v1(), v0()); 092 093 for (int i = 0; i < 3; i++) { 094 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 095 List<V> expectedValues = copyToList(values); 096 097 Entry<K, Collection<V>> asMapEntry = multimap().asMap().entrySet().iterator().next(); 098 List<V> asMapValue = (List<V>) asMapEntry.getValue(); 099 asMapValue.remove(i); 100 expectedValues.remove(i); 101 102 assertGet(k0(), expectedValues); 103 } 104 } 105}