Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 原因:不存在类型变量T的实例,因此void符合使用mockito的要求_Java_Spring_Spring Boot_Junit_Mockito - Fatal编程技术网

Java 原因:不存在类型变量T的实例,因此void符合使用mockito的要求

Java 原因:不存在类型变量T的实例,因此void符合使用mockito的要求,java,spring,spring-boot,junit,mockito,Java,Spring,Spring Boot,Junit,Mockito,我想在运行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 对于void方法,我认为需要使用doThrow语法 因此,在您的情

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

对于void方法,我认为需要使用
doThrow
语法

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

doThrow(BookingException.builder().build())
.何时(预订)
.验证(任何());

我希望这能有所帮助。

上帝想象一下,如果这个莫基托的错误只是提供了一个提示,那么人的寿命会节省多少!我越来越讨厌java。。。