September 2019
Intermediate to advanced
816 pages
18h 47m
English
Testing a method that takes a lambda as a parameter can be accomplished by passing different lambdas to this method. For example, let's assume that we have the following functional interface:
@FunctionalInterfacepublic interface Replacer<String> { String replace(String s);}
Let's also assume that we have a method that takes lambdas of the String -> String type, as follows:
public static List<String> replace( List<String> list, Replacer<String> r) { List<String> result = new ArrayList<>(); for (String s: list) { result.add(r.replace(s)); } return result;}
Now, let's write a JUnit test for this method using two lambdas:
@Testpublic void testReplacer() throws Exception { List<String> names ...