【发布时间】:2021-02-04 12:29:00
【问题描述】:
我在OneServiceImpl 类中有一个方法,如下所示。在那个类中,我从另一个类调用接口方法。
public class OneServiceImpl {
//created dependency
final private SecondService secondService;
public void sendMessage(){
secondService.validateAndSend(5)
}
}
public interface SecondService() {
public Status validateAndSend(int length);
}
public class SecondServiceImpl {
@Override
public Status ValidateAndSend(int length) {
if(length < 5) {
throw new BadRequestException("error", "error");
}
}
}
现在,当我尝试对 OneServiceImpl 执行单元测试时,我无法抛出 BadRequestException。
when(secondService.validateAndSend(6)).thenThrow(BadRequestException.class);
【问题讨论】:
标签: spring-boot junit mockito