我正在测试类ClassToTest,它在内部调用类B的静态方法,当参数为null时抛出异常。 示例代码:
public final class ClassToTest{
public returnObject apply(final Optional<classC> classC, final ReturnObject returnObject){
throwException when classC.isNull();
throwException when returnObject.isNull();
if(classC.isPresent()){
try{
ClassB.validate(classC.get(),returnObject);
}catch(Exception e){
}
}
public classB{
public static void validate(final ClassC classC, ReturnObject returnObject){
throwException.when(classC.isNull());
throwException.when(returnObject.isNull());
throwException.when(classC.getReturn().isNull());
if(syx.successful){
checkForNull(classC,returnObject)
}
private static void checkForNull(Classx classx, ReturnObject returnObject){
throwException.when(classx.getReturn().getCollectionObject().isNull());
throwException.when(classx.getReturn().getgetCollectionObject().getResponse().isNUll();
}
}
我不能把实际代码放在这里。 在要测试的类中,我想忽略使用doIgnore()调用validate方法。我尝试了以下方式,但我得到了例外。
@Mock private ClassB classB;
ClassB classBspy= PowerMockito.spy(classB);
Mockito.doNothing().when(classBspy).validate(classC,returnObject);
我遇到以下异常:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here: (at doNothing line)
调试时,在throwException.when(classC.getReturn().isNull()