@Test(expected = UserNotFoundException.class) public void loginShouldThrowUserNotFoundExceptionBecauseOfNonUniqueResultException() throws UserNotFoundException { given(userRepository.findByUserNameAndUserPassword(USER_NAME, USER_PASSWORD)) .willThrow(NonUniqueResultException.class); userService.login(userDTO); }
@Transactional(readOnly = true) public UserDTO login(UserDTO user) throws UserNotFoundException { Assert.notNull(user); Assert.notNull(user.getName()); Assert.notNull(user.getPassword()); UserEntity userEntity; try { userEntity = userRepository.findByUserNameAndUserPassword(user.getName(), user.getPassword()); if (userEntity == null) { throw new UserNotFoundException(); } } catch (NoResultException | EmptyResultDataAccessException | NonUniqueResultException e) { throw new UserNotFoundException(e); } catch (UserNotFoundException e) { throw e; } catch (Exception e) { log.error("User failed to login", e); throw new BackendException(e); } UserDTO userDTO = converterService.convert(userEntity, UserDTO.class); return userDTO; }
UserServiceImpl implements UserService { @Transactional(readOnly = true) public UserDTO login(UserDTO user) throws UserNotFoundException { Assert.notNull(user); Assert.notNull(user.getName()); Assert.notNull(user.getPassword()); UserEntity userEntity; try { userEntity = userRepository.findByUserNameAndUserPassword(user.getName(), user.getPassword()); if (userEntity == null) { throw new UserNotFoundException(); } } catch (NoResultException | EmptyResultDataAccessException | NonUniqueResultException e) { throw new UserNotFoundException(e); } catch (UserNotFoundException e) { throw e; } catch (Exception e) { log.error("User failed to login", e); throw new BackendException(e); } UserDTO userDTO = converterService.convert(userEntity, UserDTO.class); return userDTO; } }
UserServiceImpl implements UserService { @Transactional(readOnly = true) public UserDTO login(UserDTO user) throws UserNotFoundException { Assert.notNull(user); Assert.notNull(user.getName()); Assert.notNull(user.getPassword()); UserEntity userEntity; try { userEntity = userRepository.findByUserNameAndUserPassword(user.getName(), user.getPassword()); if (userEntity == null) { throw new UserNotFoundException(); } } catch (NoResultException | EmptyResultDataAccessException | NonUniqueResultException e) { throw new UserNotFoundException(e); } catch (UserNotFoundException e) { throw e; } catch (Exception e) { log.error("User failed to login", e); throw new BackendException(e); } UserDTO userDTO = converterService.convert(userEntity, UserDTO.class); return userDTO; }  }
UserServiceImpl implements UserService { @Transactional(readOnly = true) public UserDTO login(UserDTO user) throws UserNotFoundException { Assert.notNull(user); Assert.notNull(user.getName()); Assert.notNull(user.getPassword()); UserEntity userEntity; try { userEntity = userRepository.findByUserNameAndUserPassword(user.getName(), user.getPassword()); if (userEntity == null) { throw new UserNotFoundException(); } } catch (NoResultException | EmptyResultDataAccessException | NonUniqueResultException e) { throw new UserNotFoundException(e); } catch (UserNotFoundException e) { throw e; } catch (Exception e) { log.error("User failed to login", e); throw new BackendException(e); } UserDTO userDTO = converterService.convert(userEntity, UserDTO.class); return userDTO; }  @Transactional(readOnly = true) UserDTO login(UserDTO user); @Transactional @Override Long saveOrUpdate(UserDTO userDTO); @Transactional(readOnly = true) @Override UserDTO findUserByName(String username); }
UserServiceImpl implements UserService { @Transactional(readOnly = true) public UserDTO login(UserDTO user) throws UserNotFoundException { Assert.notNull(user); Assert.notNull(user.getName()); Assert.notNull(user.getPassword()); UserEntity userEntity; try { userEntity = userRepository.findByUserNameAndUserPassword(user.getName(), user.getPassword()); if (userEntity == null) { throw new UserNotFoundException(); } } catch (NoResultException | EmptyResultDataAccessException | NonUniqueResultException e) { throw new UserNotFoundException(e); } catch (UserNotFoundException e) { throw e; } catch (Exception e) { log.error("User failed to login", e); throw new BackendException(e); } UserDTO userDTO = converterService.convert(userEntity, UserDTO.class); return userDTO; }  @Transactional(readOnly = true) UserDTO login(UserDTO user); @Transactional @Override Long saveOrUpdate(UserDTO userDTO); @Transactional(readOnly = true) @Override UserDTO findUserByName(String username);  }