@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); }
@Test public void collect_target() { ImmutableCollection<Integer> integers = this.classUnderTest(); MutableCollection<String> strings = this.<String>newMutable(); integers.forEach( (Procedure<Integer>) each -> { strings.add(each.toString()); }); MutableCollection<String> target = this.<String>newMutable(); MutableCollection<String> actual = integers.collect(Functions.getToString(), target); Assert.assertEquals(strings, actual); Assert.assertSame(target, actual); }
@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); }
@Test public void collect() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals(integers, integers.collect(Functions.getIntegerPassThru())); }