@Override
 @Test
 public void iteratorRemove() {
   MutableSortedBag<Integer> bag = this.newWith(-1, 0, 1, 1, 2);
   Iterator<Integer> iterator = bag.iterator();
   Verify.assertThrows(UnsupportedOperationException.class, iterator::remove);
 }
 @Override
 @Test
 public void testClone() {
   MutableSortedBag<Integer> set = this.newWith(1, 2, 3);
   MutableSortedBag<Integer> clone = set.clone();
   Assert.assertSame(set, clone);
   Verify.assertSortedBagsEqual(set, clone);
 }
 @SafeVarargs
 @Override
 protected final <T> MutableSortedBag<T> newWithOccurrences(
     ObjectIntPair<T>... elementsWithOccurrences) {
   MutableSortedBag<T> bag = TreeBag.newBag();
   for (int i = 0; i < elementsWithOccurrences.length; i++) {
     ObjectIntPair<T> itemToAdd = elementsWithOccurrences[i];
     bag.addOccurrences(itemToAdd.getOne(), itemToAdd.getTwo());
   }
   return bag.asUnmodifiable();
 }
  @Test
  public void toSortedBagBy_empty() {
    ImmutableBag<Integer> immutableBag = Bags.immutable.of();

    Function<Integer, Integer> function = object -> object * -1;
    MutableSortedBag<Integer> sortedBag = immutableBag.toSortedBagBy(function);
    sortedBag.addOccurrences(1, 3);
    sortedBag.addOccurrences(10, 2);

    Verify.assertSortedBagsEqual(
        TreeBag.newBagWith(Comparators.byFunction(function), 10, 10, 1, 1, 1), sortedBag);
  }
  @Test
  public void toSortedBag_empty() {
    ImmutableBag<String> immutableBag = Bags.immutable.of();

    MutableSortedBag<String> sortedBag =
        immutableBag.toSortedBag(Comparators.reverseNaturalOrder());
    sortedBag.addOccurrences("apple", 3);
    sortedBag.addOccurrences("orange", 2);

    Verify.assertSortedBagsEqual(
        TreeBag.newBagWith(
            Comparators.reverseNaturalOrder(), "orange", "orange", "apple", "apple", "apple"),
        sortedBag);
  }
  @Override
  @Test
  public void toSortedBag() {
    ImmutableBag<String> immutableBag = this.newBag();
    MutableSortedBag<String> sortedBag = immutableBag.toSortedBag();

    Verify.assertSortedBagsEqual(TreeBag.newBag(), sortedBag);

    MutableSortedBag<String> reverse = immutableBag.toSortedBag(Comparator.<String>reverseOrder());
    Verify.assertSortedBagsEqual(TreeBag.newBag(Comparator.<String>reverseOrder()), reverse);

    ImmutableBag<String> immutableBag1 = this.newBag();
    MutableSortedBag<String> sortedBag1 = immutableBag1.toSortedBag(Comparator.reverseOrder());
    Verify.assertSortedBagsEqual(TreeBag.newBag(), sortedBag1.toSortedBag());

    ImmutableBag<String> immutableBag2 = this.newBag();
    MutableSortedBag<String> sortedBag2 = immutableBag2.toSortedBag(Comparator.reverseOrder());
    Verify.assertSortedBagsEqual(TreeBag.newBag(Comparator.<String>reverseOrder()), sortedBag2);
  }
  @Override
  @Test
  public void iterator() {
    MutableSortedBag<Integer> bag = this.newWith(-1, 0, 1, 1, 2);
    Iterator<Integer> iterator = bag.iterator();
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(Integer.valueOf(-1), iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(Integer.valueOf(0), iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(Integer.valueOf(1), iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(Integer.valueOf(1), iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(Integer.valueOf(2), iterator.next());
    Assert.assertFalse(iterator.hasNext());

    MutableSortedBag<Integer> revBag =
        this.newWith(Comparators.reverseNaturalOrder(), -1, 0, 1, 1, 2);
    Iterator<Integer> revIterator = revBag.iterator();
    Assert.assertTrue(revIterator.hasNext());
    Assert.assertEquals(Integer.valueOf(2), revIterator.next());
    Assert.assertTrue(revIterator.hasNext());
    Assert.assertEquals(Integer.valueOf(1), revIterator.next());
    Assert.assertTrue(revIterator.hasNext());
    Assert.assertEquals(Integer.valueOf(1), revIterator.next());
    Assert.assertTrue(revIterator.hasNext());
    Assert.assertEquals(Integer.valueOf(0), revIterator.next());
    Assert.assertTrue(revIterator.hasNext());
    Assert.assertEquals(Integer.valueOf(-1), revIterator.next());
    Assert.assertFalse(revIterator.hasNext());

    Iterator<Integer> iterator3 =
        this.newWith(Comparators.reverseNaturalOrder(), 2, 1, 1, 0, -1).iterator();
    Verify.assertThrows(UnsupportedOperationException.class, iterator3::remove);
    Assert.assertEquals(Integer.valueOf(2), iterator3.next());
    Verify.assertThrows(UnsupportedOperationException.class, iterator3::remove);
  }
 @Test
 public void testAsUnmodifiable() {
   Verify.assertInstanceOf(UnmodifiableSortedBag.class, this.newWith().asUnmodifiable());
   MutableSortedBag<Object> bag = this.newWith();
   Assert.assertSame(bag, bag.asUnmodifiable());
 }