The answer is true|| true
was not covered.
This is because once the JVM has found the first condition to be true, then it won't run the second condition (it's optimized) which means that portion of the code is never run.
As Maroun said, 3 out of 4 branches will allow the conditional to pass. If you're still worried about code coverage, you can refactor the conditional to be a &&
instead of a ||
.
(x || y)
is the same as (!(!x && !y))
and this will allow you to test all conditions since there are only three branches now.
The original form of the conditional is often seen in guard statements:
if (obj == null || obj.hasError())
{
throw new RuntimeException();
}
This will never allow you to check if obj
is null
AND has an error because it will throw a Null Pointer Exception.
If code coverage is important, then just use this form:
if (!(obj != null && !obj.hasError()))
{
throw new RuntimeException();
}