'junit test for a method

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:

@FunctionalInterface
public 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, how can i write a JUnit test for this method using two lambdas ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source