UserDAO { public User getById(Long id) throws NotFoundException { User user = userRepository.findById(id).orElse(null); if (user == null) { throw new NotFoundException("Could not find the user with the ID " + id + "."); } return user; } @Autowired  UserDAO(UserRepository userRepository, FileDAO fileDAO, ProjectDAO projectDAO,
                   ProjectRepository projectRepository); void create(User newUser); List<User> getAll(); List<User> getAllByRole(UserRole role); User getById(Long id); User getByEmail(String email); User getByUsername(String username); void update(User user); void delete(User authUser, Long id); void delete(User authUser, List<Long> userIds);  }
@Test public void shouldGetByID() throws NotFoundException { User user = createUser(); BDDMockito.given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); User userFromDB = userDAO.getById(user.getId()); Assert.assertEquals(user, userFromDB); }
@Test(expected = NotFoundException.class) public void shouldThrowAnExceptionIfTheUserCanNotBeFoundByID() throws NotFoundException { userDAO.getById((long) TEST_USER_COUNT); }