Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 如何解决junit中可能缺少的thenReturn()异常_Java_Spring_Junit_Mockito - Fatal编程技术网

Java 如何解决junit中可能缺少的thenReturn()异常

Java 如何解决junit中可能缺少的thenReturn()异常,java,spring,junit,mockito,Java,Spring,Junit,Mockito,有人能帮助解决下面提到的异常吗 当短截线位于上述线下方时 Mockito.doNothing().when(customerRepository.save(customerProduct)) 建议我在这里正确执行 E.g. thenReturn() may be missing. 正确的短截线示例: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(

有人能帮助解决下面提到的异常吗 当短截线位于上述线下方时

Mockito.doNothing().when(customerRepository.save(customerProduct)) 
建议我在这里正确执行

E.g. thenReturn() may be missing.
正确的短截线示例:

    when(mock.isOk()).thenReturn(true);
    when(mock.isOk()).thenThrow(exception);
    doThrow(exception).when(mock).someVoidMethod();
提示:

 1. missing thenReturn()
 2. you are trying to stub a final method, which is not supported
 3. you are stubbing the behaviour of another mock inside before 'thenReturn' instruction is completed
tell
doNothing()
方法应如下使用:

doNothing().when(mock.method())
因此,在您的情况下,您可能需要尝试以下方法:

Mockito.doNothing().when(customerRepository)
.save(customerProduct)

它不应该是
Mockito.doNothing().when(customerRepository).save(customerProduct)