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 @MapFeature.Require(SUPPORTS_REMOVE) 042 @CollectionSize.Require(SEVERAL) 043 public void testMultimapRemoveDeletesFirstOccurrence() { 044 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 045 046 List<V> list = multimap().get(k0()); 047 multimap().remove(k0(), v0()); 048 assertContentsInOrder(list, v1(), v0()); 049 } 050 051 @MapFeature.Require(SUPPORTS_REMOVE) 052 @CollectionSize.Require(SEVERAL) 053 public void testRemoveAtIndexFromGetPropagates() { 054 List<V> values = Arrays.asList(v0(), v1(), v0()); 055 056 for (int i = 0; i < 3; i++) { 057 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 058 List<V> expectedValues = copyToList(values); 059 060 multimap().get(k0()).remove(i); 061 expectedValues.remove(i); 062 063 assertGet(k0(), expectedValues); 064 } 065 } 066 067 @MapFeature.Require(SUPPORTS_REMOVE) 068 @CollectionSize.Require(SEVERAL) 069 public void testRemoveAtIndexFromAsMapPropagates() { 070 List<V> values = Arrays.asList(v0(), v1(), v0()); 071 072 for (int i = 0; i < 3; i++) { 073 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 074 List<V> expectedValues = copyToList(values); 075 076 List<V> asMapValue = (List<V>) multimap().asMap().get(k0()); 077 asMapValue.remove(i); 078 expectedValues.remove(i); 079 080 assertGet(k0(), expectedValues); 081 } 082 } 083 084 @MapFeature.Require(SUPPORTS_REMOVE) 085 @CollectionSize.Require(SEVERAL) 086 public void testRemoveAtIndexFromAsMapEntrySetPropagates() { 087 List<V> values = Arrays.asList(v0(), v1(), v0()); 088 089 for (int i = 0; i < 3; i++) { 090 resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0())); 091 List<V> expectedValues = copyToList(values); 092 093 Entry<K, Collection<V>> asMapEntry = multimap().asMap().entrySet().iterator().next(); 094 List<V> asMapValue = (List<V>) asMapEntry.getValue(); 095 asMapValue.remove(i); 096 expectedValues.remove(i); 097 098 assertGet(k0(), expectedValues); 099 } 100 } 101}