UserServiceImpl implements UserService { @Override @Transactional(rollbackFor = Throwable.class) public void updateUser(User user) throws FieldValidationException, UserNotFoundException { Preconditions.checkArgument(user != null, "User reference required"); Preconditions.checkArgument(StringUtils.hasText(user.getUuid()), "User uuid must be provided"); validateUser(user); boolean isUpdatedSuccessfully; try { isUpdatedSuccessfully = userDao.updateUser(user); eventBus.post(EntityChangedEvent.updated(user)); } catch (DuplicateKeyException dke) { throw new FieldValidationException(new DuplicateUserValidationError(User.FN_EMAIL)); } catch (Throwable t) { String msg = String.format("Failed to update user '%s'", user.getUuid()); throw new UserServiceUnexpectedException(msg, t); } if (!isUpdatedSuccessfully) { throw new UserNotFoundException(user.getUuid()); } }  @Override @Transactional(rollbackFor = Throwable.class) User createUser(User userTemplate); @Override User getUserByUuid(String userUuid); @Override User getUserByEmail(String userEmail); @Override PaginatedList<User> findUsersByDisplayNamePartial(String displayNamePartial, PagerParams pagerParams); @Override @Transactional(rollbackFor = Throwable.class) void updateUser(User user); @Override @Transactional(rollbackFor = Throwable.class) void deleteUserByUuid(String userUuid); UserDao getUserDao(); void setUserDao(UserDao userDao); EventBus getEventBus(); @Required void setEventBus(EventBus eventBus); StringIdGenerator getStringIdGenerator(); @Autowired(required = false) void setStringIdGenerator(StringIdGenerator stringIdGenerator);  }
@Test(expected = IllegalArgumentException.class) public void testUpdateUser_defensive_iaeOnInvalidArgument() throws Exception { UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl(); fixture.updateUser(null); fail(); }
@Test(expected = IllegalArgumentException.class) public void testUpdateUser_defensive_iaeOnInvalidUserInfo() throws Exception { UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl(); fixture.updateUser(UserFactory.createNewUserTemplate()); fail(); }
@Test(expected = FieldValidationException.class) public void testUpdateUser_blackbox_expectFieldValidationExceptionOnDuplicateUser() throws Exception { UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl(); fixture.updateUser(UserFactory.createDuplicateUser()); fail(); }