@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);
  }
 @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();
 }