### Question:
UserServiceImpl implements UserService { @Transactional @Override public User create(User user, String rawPassword) { Assert.notNull(user, "user must not be null"); String username = user.getUsername(); if (userRepository.exists(username)) { ResultMessages messages = ResultMessages.error() .add(MessageKeys.E_CT_US_8103, username); throw new BusinessException(messages); } String email = user.getEmail(); if (userRepository.countByEmail(email) > 0) { ResultMessages messages = ResultMessages.error() .add(MessageKeys.E_CT_US_8104, email); throw new BusinessException(messages); } checkRoles(user); String encodedPassword = passwordEncoder.encode(rawPassword); user.setPassword(encodedPassword); DateTime now = dateFactory.newDateTime(); user.setCreatedDate(now); user.setLastModifiedDate(now); userRepository.save(user); return user; }  @Override User findOne(String username); @Override User findOneByUsernameOrEmail(String usernameOrEmail); @Override Page<User> findPage(Pageable pageable); @Transactional @Override User create(User user, String rawPassword); @Transactional @Override User update(String username, User updatedUser,
                       String updatedRawPassword); @Transactional @Override User updateWithoutPassword(String username, User updatedUser); @Transactional @Override void delete(String username);  }### Answer:
@Test(expected = BusinessException.class) @Transactional public void testCreate_already_exist() { User user = new User("admin", null, "testuser@example.com", true, false, "Test", "User", new HashSet<Role>()); user.getRoles().add(new Role(2)); userService.create(user, "password"); }
@Test(expected = BusinessException.class) @Transactional public void testCreate_email_is_used() { User user = new User("testuser2", null, "admin@example.com", true, false, "Test", "User", null); user.setRoles(Collections.singleton(new Role(2))); userService.create(user, "password"); }
@Test(expected = BusinessException.class) @Transactional public void testCreate_illeagal_role() { User user = new User("testuser2", null, "testuser2@example.com", true, false, "Test", "User", null); user.setRoles(Collections.singleton(new Role(100))); userService.create(user, "password"); }
@Test @Rollback(false) @Transactional public void testCreate() { User user = new User("testuser", null, "testuser@example.com", true, false, "Test", "User", new HashSet<Role>()); user.getRoles().add(new Role(2)); userService.create(user, "password"); }