Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coverage report in Java 8

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?

like image 931
Gábor Lipták Avatar asked Feb 24 '16 09:02

Gábor Lipták


1 Answers

At least Clover seems to support coverage for closures. See this blog entry!

Example in Intellij:

enter image description here

like image 106
Gábor Lipták Avatar answered Sep 29 '22 12:09

Gábor Lipták