SetMultimapPutTester.java revision 3c77433663281544363151bf284b0240dfd22a42
1/*
2 * Copyright (C) 2012 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14
15package com.google.common.collect.testing.google;
16
17import static com.google.common.collect.testing.Helpers.copyToList;
18import static com.google.common.collect.testing.Helpers.copyToSet;
19import static com.google.common.collect.testing.features.CollectionSize.ZERO;
20import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
21
22import com.google.common.annotations.GwtCompatible;
23import com.google.common.collect.SetMultimap;
24import com.google.common.collect.testing.features.CollectionSize;
25import com.google.common.collect.testing.features.MapFeature;
26
27import java.util.List;
28import java.util.Map.Entry;
29import java.util.Set;
30
31/**
32 * Tests for {@link SetMultimap#replaceValues}.
33 *
34 * @author Louis Wasserman
35 */
36@GwtCompatible
37public class SetMultimapPutTester<K, V>
38    extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {
39  // Tests for non-duplicate values are in MultimapPutTester
40
41  @MapFeature.Require(SUPPORTS_PUT)
42  @CollectionSize.Require(absent = ZERO)
43  public void testPutDuplicateValue() {
44    List<Entry<K, V>> entries = copyToList(multimap().entries());
45
46    for (Entry<K, V> entry : entries) {
47      resetContainer();
48      K k = entry.getKey();
49      V v = entry.getValue();
50
51      Set<V> values = multimap().get(k);
52      Set<V> expectedValues = copyToSet(values);
53
54      assertFalse(multimap().put(k, v));
55      assertEquals(expectedValues, values);
56      assertGet(k, expectedValues);
57    }
58  }
59}
60