Mockito-未完成的存根

时间:2018-07-06 14:55:39

标签: java mockito stubbing

我得到一个带有以下代码的UnfinishedStubbingException

Mockito.when(repository.findAll(Mockito.any(Pageable.class)))
    .thenReturn(BusinessEntityMockGenerator.createPageResponse(bd, null));

奇怪的是我在Spring Boot 1.3中没有得到这个错误。我刚刚升级到Spring Boot 2.0,现在出现此错误。

有什么想法吗?谢谢!

编辑:它也给出错误Pageable must not be null!

1 个答案:

答案 0 :(得分:1)

我不确定BusinessEntityMockGenerator在做什么,但是尝试分离页面响应的方法调用:

Object toReturn = BusinessEntityMockGenerator.createPageResponse(bd, null);
Mockito.when(repository.findAll(Mockito.any(Pageable.class))).thenReturn(toReturn);

您也可以尝试:

Object toReturn = BusinessEntityMockGenerator.createPageResponse(bd, null);
Mockito.doReturn(toReturn).when(repository).findAll(Mockito.any(Pageable.class))