View Javadoc
1   /*
2    * Copyright (C) 2013 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  
15  package com.google.common.collect.testing.google;
16  
17  import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES;
18  import static com.google.common.collect.testing.features.CollectionSize.ZERO;
19  
20  import com.google.common.annotations.GwtCompatible;
21  import com.google.common.collect.testing.features.CollectionFeature;
22  import com.google.common.collect.testing.features.CollectionSize;
23  import com.google.common.testing.EqualsTester;
24  
25  /**
26   * Tests for {@code Multiset.equals} and {@code Multiset.hashCode}.
27   *
28   * @author Louis Wasserman
29   */
30  @GwtCompatible
31  public class MultisetEqualsTester<E> extends AbstractMultisetTester<E> {
32    public void testEqualsSameContents() {
33      new EqualsTester()
34          .addEqualityGroup(
35              getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
36          .testEquals();
37    }
38  
39    @CollectionSize.Require(absent = ZERO)
40    public void testNotEqualsEmpty() {
41      new EqualsTester()
42          .addEqualityGroup(getMultiset())
43          .addEqualityGroup(getSubjectGenerator().create())
44          .testEquals();
45    }
46  
47    public void testHashCodeMatchesEntrySet() {
48      assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
49    }
50  
51    @CollectionSize.Require(absent = ZERO)
52    @CollectionFeature.Require(ALLOWS_NULL_VALUES)
53    public void testEqualsMultisetWithNullValue() {
54      new EqualsTester()
55          .addEqualityGroup(getMultiset())
56          .addEqualityGroup(
57              getSubjectGenerator().create(createArrayWithNullElement()),
58              getSubjectGenerator().create(createArrayWithNullElement()))
59          .testEquals();
60    }
61  }