I have added two conditions in code:
n the code if
gets covered properly, however I am not able to cover the else if
part
public Optional < Flavors > callIcecream() {
try {
if (icecream == 1) {
//do something
return Optional.of(someString)
} else if (icecream > 1) {
//do something else
log.error("");
}
return empty();
} catch (Exception e) {
throw new IceCreamException()
}
}
I have added below code for mutation coverage
@Test
void getIcreamValues(){
when(abc.buyIcream(Mockito.anyString())).thenReturn(getIcream(1));
final Optional<Falvors>icecreamInfo = xyz.callIcecream();
assertThat(icecreamInfo).isPresent();
}
@Test
void getIcreamValues(){
when(abc.buyIcream(Mockito.anyString())).thenReturn(getIcream(0));
final Optional<Falvors>icecreamInfo = xyz.callIcecream();
assertThat(icecreamInfo).isEmpty();
}
@Test
void getIcreamValues(){
when(abc.buyIcream(Mockito.anyString())).thenReturn(getIcream(2));
final Optional<Falvors>icecreamInfo = xyz.callIcecream();
assertThat(icecreamInfo).isPresent();
}