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.Helpers.copyToSet; 019import static com.google.common.collect.testing.features.CollectionSize.ZERO; 020import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES; 021import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; 022 023import com.google.common.annotations.GwtCompatible; 024import com.google.common.collect.SetMultimap; 025import com.google.common.collect.testing.features.CollectionSize; 026import com.google.common.collect.testing.features.MapFeature; 027import java.util.List; 028import java.util.Map.Entry; 029import java.util.Set; 030import org.junit.Ignore; 031 032/** 033 * Tests for {@link SetMultimap#replaceValues}. 034 * 035 * @author Louis Wasserman 036 */ 037@GwtCompatible 038@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 039public class SetMultimapPutTester<K, V> extends AbstractMultimapTester<K, V, SetMultimap<K, V>> { 040 // Tests for non-duplicate values are in MultimapPutTester 041 042 @MapFeature.Require(SUPPORTS_PUT) 043 @CollectionSize.Require(absent = ZERO) 044 public void testPutDuplicateValuePreservesSize() { 045 assertFalse(multimap().put(k0(), v0())); 046 assertEquals(getNumElements(), multimap().size()); 047 } 048 049 @MapFeature.Require(SUPPORTS_PUT) 050 public void testPutDuplicateValue() { 051 List<Entry<K, V>> entries = copyToList(multimap().entries()); 052 053 for (Entry<K, V> entry : entries) { 054 resetContainer(); 055 K k = entry.getKey(); 056 V v = entry.getValue(); 057 058 Set<V> values = multimap().get(k); 059 Set<V> expectedValues = copyToSet(values); 060 061 assertFalse(multimap().put(k, v)); 062 assertEquals(expectedValues, values); 063 assertGet(k, expectedValues); 064 } 065 } 066 067 @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) 068 @CollectionSize.Require(absent = ZERO) 069 public void testPutDuplicateValue_null() { 070 initMultimapWithNullValue(); 071 assertFalse(multimap().put(getKeyForNullValue(), null)); 072 expectContents(createArrayWithNullValue()); 073 } 074}