gpt4 book ai didi

java - 原因: no instance(s) of type variable(s) T exist so that void conforms to using mockito

转载 作者:行者123 更新时间:2023-12-03 10:04:10 26 4
gpt4 key购买 nike

我想在运行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

最佳答案

对于无效的方法,我认为您需要使用doThrow语法。

因此,在您的情况下,它将是:

doThrow(BookingException.builder().build())
.when(booking)
.validate(any());

我希望这有帮助。

关于java - 原因: no instance(s) of type variable(s) T exist so that void conforms to using mockito,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60977373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com