@Test
 public void selectByOccurrences() {
   MutableBag<Integer> integers =
       UnmodifiableBag.of(HashBag.newBagWith(1, 1, 1, 1, 2, 2, 2, 3, 3, 4));
   Assert.assertEquals(
       iBag(1, 1, 1, 1, 3, 3), integers.selectByOccurrences(IntPredicates.isEven()));
 }
 @Override
 @Test
 public void collectShort() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       ShortHashBag.newBagWith((short) 1, (short) 2, (short) 2, (short) 3, (short) 3, (short) 3),
       integers.collectShort(PrimitiveFunctions.unboxIntegerToShort()));
 }
 @Override
 @Test
 public void collectLong() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       LongHashBag.newBagWith(1L, 2L, 2L, 3L, 3L, 3L),
       integers.collectLong(PrimitiveFunctions.unboxIntegerToLong()));
 }
 @Override
 @Test
 public void collectFloat() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       FloatHashBag.newBagWith(1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f),
       integers.collectFloat(PrimitiveFunctions.unboxIntegerToFloat()));
 }
 @Override
 @Test
 public void collectDouble() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       DoubleHashBag.newBagWith(1.0d, 2.0d, 2.0d, 3.0d, 3.0d, 3.0d),
       integers.collectDouble(PrimitiveFunctions.unboxIntegerToDouble()));
 }
 @Override
 @Test
 public void collectByte() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       ByteHashBag.newBagWith((byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 3, (byte) 3),
       integers.collectByte(PrimitiveFunctions.unboxIntegerToByte()));
 }
 @Override
 @Test
 public void collectBoolean() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(0, 1, 2, 2));
   Assert.assertEquals(
       BooleanHashBag.newBagWith(false, true, true, true),
       integers.collectBoolean(PrimitiveFunctions.integerIsPositive()));
 }
 @Test
 public void forEachKeyValue() {
   MutableBag<String> collection = Bags.mutable.of();
   Multimap<Integer, String> multimap =
       this.newMultimapWithKeysValues(1, "One", 2, "Two", 3, "Three");
   multimap.forEachKeyValue((key, value) -> collection.add(key + value));
   Assert.assertEquals(HashBag.newBagWith("1One", "2Two", "3Three"), collection);
 }
 @Test
 public void equalsAndHashCode() {
   ImmutableBag<String> immutable = this.newBag();
   MutableBag<String> mutable = HashBag.newBag(immutable);
   Verify.assertEqualsAndHashCode(immutable, mutable);
   Assert.assertNotEquals(immutable, FastList.newList(mutable));
   Assert.assertEquals(this.newBag().toMapOfItemToCount().hashCode(), this.newBag().hashCode());
   Assert.assertNotEquals(immutable, mutable.with("5").without("1"));
 }
 @Test
 public void forEachWith() {
   MutableBag<String> result = Bags.mutable.of();
   ImmutableBag<String> bag = this.newBag();
   bag.forEachWith(
       (argument1, argument2) -> {
         result.add(argument1 + argument2);
       },
       "");
   Assert.assertEquals(bag, result);
 }
  @Test
  public void iterator() {
    ImmutableBag<String> strings = this.newBag();
    MutableBag<String> result = Bags.mutable.of();
    Iterator<String> iterator = strings.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
      String string = iterator.next();
      result.add(string);
    }
    Assert.assertEquals(strings, result);

    Verify.assertThrows(NoSuchElementException.class, iterator::next);
  }
 @Override
 @Test
 public void collectChar() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       CharHashBag.newBagWith('A', 'B', 'B', 'C', 'C', 'C'),
       integers.collectChar(
           new CharFunction<Integer>() {
             public char charValueOf(Integer integer) {
               return (char) (integer.intValue() + 64);
             }
           }));
 }
 @Test
 public void toImmutable() {
   MutableBag<?> bag = this.getCollection();
   Verify.assertInstanceOf(ImmutableBag.class, bag.toImmutable());
 }
 @Test
 public void asSynchronized() {
   MutableBag<?> bag = this.getCollection();
   Verify.assertInstanceOf(SynchronizedBag.class, bag.asSynchronized());
 }
 @Test
 public void asUnmodifiable() {
   MutableBag<?> bag = this.getCollection();
   Verify.assertInstanceOf(UnmodifiableBag.class, bag.asUnmodifiable());
 }
 @Test
 public void selectInstancesOf() {
   MutableBag<Number> numbers = UnmodifiableBag.of(HashBag.<Number>newBagWith(1, 2.0, 3, 4.0, 5));
   Assert.assertEquals(iBag(1, 3, 5), numbers.selectInstancesOf(Integer.class));
   Assert.assertEquals(iBag(1, 2.0, 3, 4.0, 5), numbers.selectInstancesOf(Number.class));
 }