On the other hand, testing a method that returns a functional interface can be interpreted as testing the behavior of that functional interface. Let's consider the following method:
public static Function<String, String> reduceStrings(
Function<String, String> ...functions) {
Function<String, String> function = Stream.of(functions)
.reduce(Function.identity(), Function::andThen);
return function;
}
Now, we can test the behavior of the returned Function<String, String> as follows:
@Test
public void testReduceStrings() throws Exception {
Function<String, String> f1 = (String s) -> s.toUpperCase();
Function<String, String> f2 = (String s) -> s.concat(" DONE");
Function<String, String> f = reduceStrings(f1, f2);
assertEquals("TEST DONE", f.apply("test"));
}