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.copyToList; 018import static com.google.common.collect.testing.features.CollectionSize.ZERO; 019import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; 020 021import com.google.common.annotations.GwtCompatible; 022import com.google.common.collect.ListMultimap; 023import com.google.common.collect.testing.features.CollectionSize; 024import com.google.common.collect.testing.features.MapFeature; 025import java.util.List; 026import java.util.Map.Entry; 027import org.junit.Ignore; 028 029/** 030 * Testers for {@link ListMultimap#put(Object, Object)}. 031 * 032 * @author Louis Wasserman 033 */ 034@GwtCompatible 035@Ignore("test runners must not instantiate and run this directly, only via suites we build") 036// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 037@SuppressWarnings("JUnit4ClassUsedInJUnit3") 038public class ListMultimapPutTester<K, V> extends AbstractListMultimapTester<K, V> { 039 // MultimapPutTester tests non-duplicate values, but ignores ordering 040 041 @MapFeature.Require(SUPPORTS_PUT) 042 public void testPutAddsValueAtEnd() { 043 for (K key : sampleKeys()) { 044 for (V value : sampleValues()) { 045 resetContainer(); 046 047 List<V> values = multimap().get(key); 048 List<V> expectedValues = copyToList(values); 049 050 assertTrue(multimap().put(key, value)); 051 expectedValues.add(value); 052 053 assertGet(key, expectedValues); 054 assertEquals(value, values.get(values.size() - 1)); 055 } 056 } 057 } 058 059 @MapFeature.Require(SUPPORTS_PUT) 060 @CollectionSize.Require(absent = ZERO) 061 public void testPutDuplicateValue() { 062 List<Entry<K, V>> entries = copyToList(multimap().entries()); 063 064 for (Entry<K, V> entry : entries) { 065 resetContainer(); 066 067 K k = entry.getKey(); 068 V v = entry.getValue(); 069 070 List<V> values = multimap().get(k); 071 List<V> expectedValues = copyToList(values); 072 073 assertTrue(multimap().put(k, v)); 074 expectedValues.add(v); 075 assertGet(k, expectedValues); 076 assertEquals(v, values.get(values.size() - 1)); 077 } 078 } 079}