MultimapContainsEntryTester.java revision 7dd252788645e940eada959bdde927426e2531c9
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 */
16
17package com.google.common.collect.testing.google;
18
19import static com.google.common.collect.testing.features.CollectionSize.ZERO;
20import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
21import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_QUERIES;
22import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
23
24import com.google.common.annotations.GwtCompatible;
25import com.google.common.collect.Multimap;
26import com.google.common.collect.testing.features.CollectionSize;
27import com.google.common.collect.testing.features.MapFeature;
28
29/**
30 * Tester for {@link Multimap#containsEntry}.
31 *
32 * @author Louis Wasserman
33 */
34@GwtCompatible
35public class MultimapContainsEntryTester<K, V>
36    extends AbstractMultimapTester<K, V, Multimap<K, V>> {
37  @CollectionSize.Require(absent = ZERO)
38  public void testContainsEntryYes() {
39    assertTrue(multimap().containsEntry(sampleKeys().e0, sampleValues().e0));
40  }
41
42  public void testContainsEntryNo() {
43    assertFalse(multimap().containsEntry(sampleKeys().e3, sampleValues().e3));
44  }
45
46  public void testContainsEntryAgreesWithGet() {
47    for (K k : sampleKeys()) {
48      for (V v : sampleValues()) {
49        assertEquals(multimap().get(k).contains(v),
50            multimap().containsEntry(k, v));
51      }
52    }
53  }
54
55  @CollectionSize.Require(absent = ZERO)
56  @MapFeature.Require({ ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES })
57  public void testContainsEntryNullYes() {
58    initMultimapWithNullKeyAndValue();
59    assertTrue(multimap().containsEntry(null, null));
60  }
61
62  @MapFeature.Require(ALLOWS_NULL_QUERIES)
63  public void testContainsEntryNullNo() {
64    assertFalse(multimap().containsEntry(null, null));
65  }
66
67  @MapFeature.Require(absent = ALLOWS_NULL_QUERIES)
68  public void testContainsEntryNullDisallowed() {
69    try {
70      multimap().containsEntry(null, null);
71      fail("Expected NullPointerException");
72    } catch (NullPointerException expected) {
73      // success
74    }
75  }
76}
77