@Test(expected=NoRecordsFoundException.class) public void doFindNullAccount() { when(repo.findById(999)).thenReturn(Optional.empty()); service.findUser(999); }
public User findUser(Integer id) { logger.debug("user.findAccount: id=" + id); Optional<User> account = user.findById(id); if (!account.isPresent()) { logger.warn("UserService.findAccount: could not find account with id: " + id); throw new NoRecordsFoundException(); } logger.info(String .format("UserService.findAccount - retrieved account with id: %s. Payload is: %s", id, account.get())); return account.get(); }
UserService { public User findUser(Integer id) { logger.debug("user.findAccount: id=" + id); Optional<User> account = user.findById(id); if (!account.isPresent()) { logger.warn("UserService.findAccount: could not find account with id: " + id); throw new NoRecordsFoundException(); } logger.info(String .format("UserService.findAccount - retrieved account with id: %s. Payload is: %s", id, account.get())); return account.get(); } }
UserService { public User findUser(Integer id) { logger.debug("user.findAccount: id=" + id); Optional<User> account = user.findById(id); if (!account.isPresent()) { logger.warn("UserService.findAccount: could not find account with id: " + id); throw new NoRecordsFoundException(); } logger.info(String .format("UserService.findAccount - retrieved account with id: %s. Payload is: %s", id, account.get())); return account.get(); }  }
UserService { public User findUser(Integer id) { logger.debug("user.findAccount: id=" + id); Optional<User> account = user.findById(id); if (!account.isPresent()) { logger.warn("UserService.findAccount: could not find account with id: " + id); throw new NoRecordsFoundException(); } logger.info(String .format("UserService.findAccount - retrieved account with id: %s. Payload is: %s", id, account.get())); return account.get(); }  User findUser(Integer id); User findUser(String username); @Cacheable(value = "authorizationCache") User findAccountprofileByAuthtoken(String token); Integer saveUser(User userRequest); Map<String, Object> login(String username, String password); User logout(String userId); }
UserService { public User findUser(Integer id) { logger.debug("user.findAccount: id=" + id); Optional<User> account = user.findById(id); if (!account.isPresent()) { logger.warn("UserService.findAccount: could not find account with id: " + id); throw new NoRecordsFoundException(); } logger.info(String .format("UserService.findAccount - retrieved account with id: %s. Payload is: %s", id, account.get())); return account.get(); }  User findUser(Integer id); User findUser(String username); @Cacheable(value = "authorizationCache") User findAccountprofileByAuthtoken(String token); Integer saveUser(User userRequest); Map<String, Object> login(String username, String password); User logout(String userId);  }