Jacoco is a coverage tool. It checks if every possible branch of the code has been covered. It doesn't complain that there is no else statement. What it complains about is that you've never executed the code with randomField
being null.
Maybe the rest of the code will break if randomField is null. Your tests aren't testing this possibility, and that's what jacoco is warning you about. Here's an example:
String foo = null;
if(randomfield != null) {
foo = randomField;
}
System.out.println(foo.toLowerCase());
If you test the code with randomField
being "hello"
, everything will go fine. But if randomField
is null, then this will cause an undesired NullPointerException. That's a bug that would be detected by testing the code with a null randomField. Since you didn't do that, jacoco is complaining.