View Javadoc
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  
17  package com.google.common.collect.testing.google;
18  
19  import static com.google.common.collect.testing.features.CollectionSize.ZERO;
20  import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
21  import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUE_QUERIES;
22  
23  import com.google.common.annotations.GwtCompatible;
24  import com.google.common.collect.Multimap;
25  import com.google.common.collect.testing.features.CollectionSize;
26  import com.google.common.collect.testing.features.MapFeature;
27  
28  /**
29   * Tester for {@link Multimap#containsValue}.
30   *
31   * @author Louis Wasserman
32   */
33  @GwtCompatible
34  public class MultimapContainsValueTester<K, V>
35      extends AbstractMultimapTester<K, V, Multimap<K, V>> {
36    @CollectionSize.Require(absent = ZERO)
37    public void testContainsValueYes() {
38      assertTrue(multimap().containsValue(v0()));
39    }
40  
41    public void testContainsValueNo() {
42      assertFalse(multimap().containsValue(v3()));
43    }
44  
45    @MapFeature.Require(ALLOWS_NULL_VALUES)
46    @CollectionSize.Require(absent = ZERO)
47    public void testContainsNullValueYes() {
48      initMultimapWithNullValue();
49      assertTrue(multimap().containsValue(null));
50    }
51  
52    @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
53    public void testContainsNullValueNo() {
54      assertFalse(multimap().containsValue(null));
55    }
56  
57    @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
58    public void testContainsNullValueFails() {
59      try {
60        multimap().containsValue(null);
61        fail("Expected NullPointerException");
62      } catch (NullPointerException expected) {
63        // success
64      }
65    }
66  }