我想在运行 void 方法时抛出异常
when(booking.validate(any())).thenThrow(BookingException.builder().build());
但我有一个编译错误:
Required type: T
Provided: void
reason: no instance(s) of type variable(s) T exist so that void conforms to T
原文由 Sandro Rey 发布,翻译遵循 CC BY-SA 4.0 许可协议
对于 void 方法,我认为您需要使用
doThrow
语法。所以在你的情况下它将是:
我希望这有帮助。