I have just started working with Java 8. I see a lot of streams and optionals. One question popped in my mind. Consider the following example taken from this oracle tutorial:
String name = computer.flatMap(Computer::getSoundcard)
.flatMap(Soundcard::getUSB)
.map(USB::getVersion)
.orElse("UNKNOWN");
Or the next one 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, which can tell me if the orElse
in the first snippet was used? Or some other, which tells me that the filter
closure was not called at all, since the list was empty? Can any report, that the method reference in forEach
was not used?
At least Clover seems to support coverage for closures. See this blog entry!
Example in Intellij:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With