コード例 #1
0
  @Test
  public void collectWith() {
    ImmutableCollection<Integer> integers = this.classUnderTest();
    ImmutableCollection<String> expected =
        integers.collect(Functions.chain(Functions.getToString(), StringFunctions.append("!")));
    ImmutableCollection<String> actual =
        integers.collectWith((argument1, argument2) -> argument1 + argument2, "!");

    Assert.assertEquals(expected, actual);
  }
コード例 #2
0
  @Test
  public void collectWith_target() {
    ImmutableCollection<Integer> integers = this.classUnderTest();
    MutableCollection<String> expected =
        this.<String>newMutable()
            .with("?")
            .withAll(
                integers.collect(
                    Functions.chain(Functions.getToString(), StringFunctions.append("!"))));
    MutableCollection<String> targetCollection = this.<String>newMutable().with("?");
    MutableCollection<String> actual =
        integers.collectWith(
            (argument1, argument2) -> argument1 + argument2, "!", targetCollection);

    Assert.assertEquals(expected, actual);
    Assert.assertSame(targetCollection, actual);
  }