Test coverage for if statement with logical or (||) - with Java's short circuiting, what's the forth condition JaCoCo wants me to cover?
You are right, this code is short-circuiting. It's compiled into bytecode roughly like this (assuming Java has goto):
if(TheEnum.A.equals(myEnum)) goto ok;
if(!TheEnum.B.equals(myEnum)) goto end;
ok:
// body of if statement
end:
So as JaCoCo analyzes the bytecode, from its point of view you have the two independent checks: first if
and second if
, which generate four possible branches. You may consider this as a JaCoCo bug, but I guess it's not very easy to fix this robustly and it is not very disturbing, so you can live with it.