I'm writing a switch statement within java 7 that varies based on a string. The code and test itself are rather trivial, but for some reason Cobertura (and Eclemma) both indicate I've missed branches within the switch.
The following code indicates I've missed 3 of 10 branches:
public String decodeQuestionResponseType(final String questionResponseType){
switch (questionResponseType) {
case "multipleChoiceResponse":
return "multipleChoice";
case "textResponse":
return "text";
case "photoResponse":
return "photo";
default:
return "none";
}
}
@Test
public void testDecoder(){
assertEquals("multipleChoice", decodeQuestionResponseType("multipleChoiceResponse"));
assertEquals("text", decodeQuestionResponseType("textResponse"));
assertEquals("photo", decodeQuestionResponseType("photoResponse"));
assertEquals("none", decodeQuestionResponseType("otherResponse"));
}
I can write using if/else statements and the test will pass. Is there something I'm missing? Why can I not get 100% branch coverage for this code?