2

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?

Kobaj
  • 311
  • 2
  • 7
  • Concerning EclEmma you can have a look at this answer: http://stackoverflow.com/a/28015212/584532 – nrainer Jan 20 '15 at 12:07

1 Answers1

3

Found this is a known bug in Cobertura, and should be fixed in version 2.1.0.

https://github.com/cobertura/cobertura/issues/79

Kobaj
  • 311
  • 2
  • 7
  • You should 'answer your own question' by accepting your answer - hey you get reputation points for that! – mikemil Mar 05 '14 at 04:59