@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);
 }
Ejemplo n.º 2
0
 @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);
 }
Ejemplo n.º 3
0
  @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);
  }