we used Junit to trigger the code-coverage and have a problem with the following construct:
public final double getAntennaDistance(EnumSample cabin) {
switch (cabin) {
case ONE:
return 10.5;// in m
case TWO:
return 129.5;
default:
System.out.println("Cab: " + cabin + " is not valid!");
return -1;
}
}
In the html-output of jacoco "all 3 branches" are covered but the switch statement is marked as yellow. And in the overview EnumSample.new Object() {} there is only a coverage of 89%. Is it possible to get 100% coverage for this case and what must we do?
I extracted a simple example (only 2 classes, and 1 testclass) from our project and zipped it to the following location: https://www.dropbox.com/s/3ijf8b90fn8e42m/coveragetestsample.7z?dl=0
To run the example Apache ANT and JDK must be in the classpath, all aother dependencies are located in the ZIP file: We use Ant version 1.10.2 and JDK 1.8.0_144. We use Powermock (not in this easy example) together with jacoco and have implemented an ant-script for this.
to clean the sample project: open console, go to coveragetestsample and put in the command "ant clean".
to build the project with jacoco coverage put in the comand "ant report".
Best Regards
Peter