MultimapPutIterableTester.java revision 3c77433663281544363151bf284b0240dfd22a42
1/*
2 * Copyright (C) 2012 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.google.common.collect.testing.google;
17
18import static com.google.common.collect.testing.features.CollectionSize.ZERO;
19import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
20
21import com.google.common.annotations.GwtCompatible;
22import com.google.common.collect.Lists;
23import com.google.common.collect.Multimap;
24import com.google.common.collect.testing.features.CollectionSize;
25import com.google.common.collect.testing.features.MapFeature;
26
27import java.util.Collections;
28import java.util.Iterator;
29
30/**
31 * Tests for {@link Multimap#putAll(Object, Iterable)}.
32 *
33 * @author Louis Wasserman
34 */
35@GwtCompatible
36public class MultimapPutIterableTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
37  @CollectionSize.Require(absent = ZERO)
38  @MapFeature.Require(SUPPORTS_PUT)
39  public void testPutAllNonEmptyOnPresentKey() {
40    multimap().putAll(sampleKeys().e0, new Iterable<V>() {
41      @Override
42      public Iterator<V> iterator() {
43        return Lists.newArrayList(sampleValues().e3, sampleValues().e4).iterator();
44      }
45    });
46    assertGet(sampleKeys().e0, sampleValues().e0, sampleValues().e3, sampleValues().e4);
47  }
48
49  @MapFeature.Require(SUPPORTS_PUT)
50  public void testPutAllNonEmptyOnAbsentKey() {
51    multimap().putAll(sampleKeys().e3, new Iterable<V>() {
52      @Override
53      public Iterator<V> iterator() {
54        return Lists.newArrayList(sampleValues().e3, sampleValues().e4).iterator();
55      }
56    });
57    assertGet(sampleKeys().e3, sampleValues().e3, sampleValues().e4);
58  }
59
60  private static final Object[] EMPTY = new Object[0];
61
62  @MapFeature.Require(SUPPORTS_PUT)
63  public void testPutAllEmptyIterableOnAbsentKey() {
64    Iterable<V> iterable = Collections.emptyList();
65
66    multimap().putAll(sampleKeys().e3, iterable);
67    expectUnchanged();
68  }
69
70  @CollectionSize.Require(absent = ZERO)
71  @MapFeature.Require(SUPPORTS_PUT)
72  public void testPutAllEmptyIterableOnPresentKey() {
73    multimap().putAll(sampleKeys().e0, Collections.<V>emptyList());
74    expectUnchanged();
75  }
76}
77