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