UserDAO { public User getByEmail(String email) throws NotFoundException { User user = userRepository.findOneByEmail(email); if (user == null) { throw new NotFoundException("Could not find the user with the email '" + email + "'!"); } 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 shouldGetByEmail() throws NotFoundException { User user = createUser(); BDDMockito.given(userRepository.findOneByEmail(user.getEmail())).willReturn(user); User userFromDB = userDAO.getByEmail(user.getEmail()); Assert.assertEquals(user, userFromDB); }
@Test(expected = NotFoundException.class) public void shouldThrowAnExceptionIfTheUserCanNotBeFoundByEmail() throws NotFoundException { User user = createUser(); BDDMockito.given(userRepository.findOneByEmail(user.getEmail())).willReturn(null); userDAO.getByEmail(user.getEmail()); }