Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2008 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.collect.testing.google;
 
 import static com.google.common.collect.testing.features.CollectionSize.ONE;
 import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
 import static com.google.common.collect.testing.features.CollectionSize.ZERO;
 
 
 import java.util.List;

A generic JUnit test which tests multiset-specific read operations. Can't be invoked directly; please see com.google.common.collect.testing.SetTestSuiteBuilder.

Author(s):
Jared Levy
 
 public class MultisetReadsTester<E> extends AbstractMultisetTester<E> {
   public void testCount_0() {
     assertEquals("multiset.count(missing) didn't return 0",
         0, getMultiset().count(.));
   }
 
   @CollectionSize.Require(absent = )
   public void testCount_1() {
     assertEquals("multiset.count(present) didn't return 1",
         1, getMultiset().count(.));
   }
 
   public void testCount_3() {
     initThreeCopies();
     assertEquals("multiset.count(thriceContained) didn't return 3",
         3, getMultiset().count(.));
   }
 
   public void testCount_null() {
     assertEquals("multiset.count(null) didn't return 0",
         0, getMultiset().count(null));
   }
 
   public void testCount_wrongType() {
     assertEquals("multiset.count(wrongType) didn't return 0",
         0, getMultiset().count(.));
   }
 
   @CollectionSize.Require(absent = )
   public void testElementSet_contains() {
     assertTrue("multiset.elementSet().contains(present) returned false",
         getMultiset().elementSet().contains(.));
   }
 
   @CollectionSize.Require(absent = )
   public void testEntrySet_contains() {
     assertTrue("multiset.entrySet() didn't contain [present, 1]",
         getMultiset().entrySet().contains(
             Multisets.immutableEntry(., 1)));
   }
 
   public void testEntrySet_contains_count0() {
     assertFalse("multiset.entrySet() contains [missing, 0]",
         getMultiset().entrySet().contains(
             Multisets.immutableEntry(., 0)));
   }
 
   public void testEntrySet_contains_nonentry() {
     assertFalse("multiset.entrySet() contains a non-entry",
         getMultiset().entrySet().contains(.));
   }
 
   public void testEntrySet_twice() {
     assertEquals("calling multiset.entrySet() twice returned unequal sets",
         getMultiset().entrySet(), getMultiset().entrySet());
   }
 
  public void testEntrySet_hashCode_size0() {
    assertEquals("multiset.entrySet() has incorrect hash code",
        0, getMultiset().entrySet().hashCode());
  }
  public void testEntrySet_hashCode_size1() {
    assertEquals("multiset.entrySet() has incorrect hash code",
        1 ^ ..hashCode(), getMultiset().entrySet().hashCode());
  }
  public void testEquals_yes() {
    assertTrue("multiset doesn't equal a multiset with the same elements",
        getMultiset().equals(HashMultiset.create(getSampleElements())));
  }
  public void testEquals_differentSize() {
    Multiset<E> other = HashMultiset.create(getSampleElements());
    other.add(.);
    assertFalse("multiset equals a multiset with a different size",
        getMultiset().equals(other));
  }
  @CollectionSize.Require(absent = )
  public void testEquals_differentElements() {
    Multiset<E> other = HashMultiset.create(getSampleElements());
    other.remove(.);
    other.add(.);
    assertFalse("multiset equals a multiset with different elements",
        getMultiset().equals(other));
  }
  public void testHashCode_size0() {
    assertEquals("multiset has incorrect hash code",
        0, getMultiset().hashCode());
  }
  public void testHashCode_size1() {
    assertEquals("multiset has incorrect hash code",
        1 ^ ..hashCode(), getMultiset().hashCode());
  }

  
Returns java.lang.reflect.Method instances for the read tests that assume multisets support duplicates so that the test of Multisets.forSet() can suppress them.
    return Arrays.asList(
        Platform.getMethod(MultisetReadsTester.class"testCount_3"));
  }
New to GrepCode? Check out our FAQ X