diff --git a/guava/src/test/java/org/baeldung/guava/GuavaFunctionalExamplesTest.java b/guava/src/test/java/org/baeldung/guava/GuavaFunctionalExamplesTest.java index 26a05a7023..f58139a974 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaFunctionalExamplesTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaFunctionalExamplesTest.java @@ -98,7 +98,7 @@ public class GuavaFunctionalExamplesTest { } } - // char predicates + // other predicates @Test public final void when_thenCorrect() { @@ -126,7 +126,7 @@ public class GuavaFunctionalExamplesTest { @Test public final void whenChainingPredicatesAndFunctions_thenCorrectResults() { - final List numbersToSort = Arrays.asList(2, 1, 11, 100, 8, 14); + final List numbers = Arrays.asList(2, 1, 11, 100, 8, 14); final Predicate acceptEvenNumber = new Predicate() { @Override public final boolean apply(final Integer number) { @@ -140,10 +140,24 @@ public class GuavaFunctionalExamplesTest { } }; - final FluentIterable powerOfTwoOnlyForEvenNumbers = FluentIterable.from(numbersToSort).filter(acceptEvenNumber).transform(powerOfTwo); + final FluentIterable powerOfTwoOnlyForEvenNumbers = FluentIterable.from(numbers).filter(acceptEvenNumber).transform(powerOfTwo); assertThat(powerOfTwoOnlyForEvenNumbers, contains(4, 10000, 64, 196)); } + @Test + public final void whenUsingFunctionComposition_thenCorrectResults() { + final List numbers = Arrays.asList(2, 3); + final Function powerOfTwo = new Function() { + @Override + public final Integer apply(final Integer input) { + return (int) Math.pow(input, 2); + } + }; + + final List result = Lists.transform(numbers, Functions.compose(powerOfTwo, powerOfTwo)); + assertThat(result, contains(16, 81)); + } + // Set+Function => Map /**