I have a Java project under Eclipse Luna, with EclEmma 2.3.1.201405111647 (latest), which use Jacoco 0.7.1, which have support for Java 8 as stated in their changelog:
"Version 2.3.1 (2014/05/11)
Fixed ASM 5.0.1 dependency conflicts with new ASM bundles in Eclipse 4.4 (GitHub #83). Upgrade to JaCoCo 0.7.1 for full Java 8 support.
I now have the following toString:
@Override
public String toString() {
// [BLOCK0]
if (0 == value) {
return "0B";
}
// [BLOCK1]
final MutableLong val = new MutableLong(value);
final StringBuilder sb = new StringBuilder();
// [BLOCK2]
Arrays.asList(TERA_BYTES, GIGA_BYTES, MEGA_BYTES, KILO_BYTES, BYTES).forEach(unit -> {
// [BLOCK3]
long divider = unit.toBytes(1);
long n = val.longValue() / divider;
if (0 != n) {
sb.append(n).append(unit.getUnitCharacter());
val.subtract(n * divider);
}
});
// [BLOCK4]
return sb.toString();
}
I won't put the Junit test, because I know it goes 100% coverage. I can prove it by moving the lamdba expression into a appendToString
method, and remplace the forEach
with a for-each for (V value : Iterable<V>)
.
The result is, when I do "Coverage as Junit Test", the following:
- BLOCK0 is all green
- BLOCK1 is all green
- BLOCK2 is green, up to the
forEach(unit -> {
- BLOCK3 is white (as if it were ignored lines)
- BLOCK4 is all green.
Can someone explain me why Jacoco can't detect coverage in lambda ?