我需要模拟对 GenericService 的 findById 方法的调用。
我有这个:
public class UserServiceImpl extends GenericServiceImpl<User Integer> implements UserService, Serializable {
....
// This call i want mock
user = findById(user.getId());
.....
// For example this one calls mockeo well. Why is not it a call to the generic service?
book = bookService.findById(id);
Run Code Online (Sandbox Code Playgroud)
问题出在第一个模拟中,因为它是对通用服务的调用。
第二个模拟也很好用
when(bookService.findById(anyInt())).thenReturn(mockedBook);
Run Code Online (Sandbox Code Playgroud)