Gábor Lipták
Gábor Lipták

Reputation: 9776

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?

Upvotes: 8

Views: 1209

Answers (1)

G&#225;bor Lipt&#225;k
G&#225;bor Lipt&#225;k

Reputation: 9776

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

Example in Intellij:

enter image description here

Upvotes: 1

Related Questions