UserService { public User loginUser(User user) { return userRepository.findByEmailAndPassword(user.getEmail(), user.getPassword()); } @Autowired  UserService(UserRepository userRepository);  UserService(); void setReviewRepository(UserRepository repository); User createUser(User user); User loginUser(User user); User findOne(Integer userId);  }
@Test public void testValidLoginUser(){ when(userRepository.findByEmailAndPassword(user.getEmail(), user.getPassword())).thenReturn(user); assertEquals(user, userService.loginUser(user)); }
@Test public void testInvalidLoginUser(){ assertEquals(null, userService.loginUser(user2)); }