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. 039@SuppressWarnings("JUnit4ClassUsedInJUnit3") 040public class SetMultimapPutTester<K, V> extends AbstractMultimapTester<K, V, SetMultimap<K, V>> { 041 // Tests for non-duplicate values are in MultimapPutTester 042 043 @MapFeature.Require(SUPPORTS_PUT) 044 @CollectionSize.Require(absent = ZERO) 045 public void testPutDuplicateValuePreservesSize() { 046 assertFalse(multimap().put(k0(), v0())); 047 assertEquals(getNumElements(), multimap().size()); 048 } 049 050 @MapFeature.Require(SUPPORTS_PUT) 051 public void testPutDuplicateValue() { 052 List<Entry<K, V>> entries = copyToList(multimap().entries()); 053 054 for (Entry<K, V> entry : entries) { 055 resetContainer(); 056 K k = entry.getKey(); 057 V v = entry.getValue(); 058 059 Set<V> values = multimap().get(k); 060 Set<V> expectedValues = copyToSet(values); 061 062 assertFalse(multimap().put(k, v)); 063 assertEquals(expectedValues, values); 064 assertGet(k, expectedValues); 065 } 066 } 067 068 @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) 069 @CollectionSize.Require(absent = ZERO) 070 public void testPutDuplicateValue_null() { 071 initMultimapWithNullValue(); 072 assertFalse(multimap().put(getKeyForNullValue(), null)); 073 expectContents(createArrayWithNullValue()); 074 } 075}