I just started working with Java 8. I see a lot of threads and options. One question arose in my head. Consider the following example taken from this oracle textbook :
String name = computer.flatMap(Computer::getSoundcard) .flatMap(Soundcard::getUSB) .map(USB::getVersion) .orElse("UNKNOWN");
Or the following, taken from here :
List<String> myList = new ArrayList(); myList .stream() .filter(s -> s.startsWith("c")) .map(String::toUpperCase) .sorted() .forEach(System.out::println);
Is there any coverage solution that can tell me if orElse was used in the first snippet? Or some other that tells me that closing the filter was not called at all since the list is empty? Can any report that the method reference in forEach not used?
java java-8 unit-testing code-coverage
Gábor Lipták
source share