for example, we have a layer of service that simple invoke the JpaRepository method. usual crud
public List<User> findAll() {
return userRepository.findAll();
}
how to correctly test such methods?
just that the service invokes the dao layer?
@Mock
private UserRepository userRepository;
@Test
public void TestfindAllInvokeUserServiceMethod(){
userService.findAll();
verify(userRepository.findAll());
}
upd:
ok, findAll() is simple example, when we using
when(userRepository.findAll()).thenReturn(usersList);
we are actually doing only a test coverage, testing the obvious things.
and a question.
do we need to test such service сrud methods?
which only invoke the methods of dao layer
The way I do it is
While you mock the repository, then you can do something like this: