Java 无法覆盖最恶劣的条件

Java 无法覆盖最恶劣的条件,java,mutation,mutation-testing,pitest,Java,Mutation,Mutation Testing,Pitest,我在代码中添加了两个条件: n代码if正确覆盖,但是我无法覆盖else if部分 public Optional < Flavors > callIcecream() { try { if (icecream == 1) { //do something return Optional.of(someString) } else if (icecream > 1) {

我在代码中添加了两个条件:
n代码
if
正确覆盖,但是我无法覆盖
else if
部分

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()
    }
}
public可选CalliceStream(){
试一试{
如果(冰淇淋==1){
//做点什么
返回可选的.of(someString)
}否则,如果(冰淇淋>1){
//做点别的
日志错误(“”);
}
返回空();
}捕获(例外e){
抛出新的冰淇淋异常()
}
}
我已经添加了以下代码用于突变覆盖率

@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();
}
@测试
void getIcreamValues(){
when(abc.buyIcream(Mockito.anyString())。然后返回(getIcream(1));
最终选项流信息=xyz.CalliceStream();
断言(icecreamInfo).isPresent();
}
@试验
void getIcreamValues(){
when(abc.buyIcream(Mockito.anyString())。然后返回(getIcream(0));
最终选项流信息=xyz.CalliceStream();
断言(icecreamInfo.isEmpty();
}
@试验
void getIcreamValues(){
when(abc.buyIcream(Mockito.anyString())。然后返回(getIcream(2));
最终选项流信息=xyz.CalliceStream();
断言(icecreamInfo).isPresent();
}

如何设置冰淇淋的值?使用从类中的函数生成的值:public Optional calliceStream(){try{final int iceCream=getValues();if(iceCream==1){//do something返回Optional.of(someString)}else if(iceCream>1){//do something log.error(“”;}return empty();}catch(异常e){throw new IceCreamException()}}这不是您问题中的代码。在调用该方法之前,我们没有看到值集。因此您需要getValues()的代码?这似乎不是突变测试问题。你只是不能让你的测试得到冰淇淋==2。不清楚如何设置icecream..可能会发布剩余的类代码?如何设置icecream的值?使用从类中的函数生成的值:public Optional calliceStream(){try{final int icecream=getValues();if(icecream==1){//do something返回Optional.of(someString)}else if(icecream>1){//do something log.error(“”;}return empty();}catch(Exception e){throw new IceCreamException()}}这不是您问题中的代码。在调用该方法之前,我们没有看到值集。因此您需要getValues()的代码?这似乎不是一个突变测试问题。您只是无法使您的测试得到icecream==2。不清楚icecream是如何设置的。可能会发布剩余的类代码?