### Question:
UserManagementServiceImpl implements UserManagementService { @Override @Transactional public boolean createUser(String userName, String password, boolean admin) { UserIndex userIndex = userService.getOrCreateUserForUsernameAndPassword(userName, password); if(userIndex == null) return false; if(admin) { User user = userIndex.getUser(); userService.enableAdminRoleForUser(user, false); disableOperatorRole(user); } log.info("User '{}' created successfully", userName); return true; }  @Override @Transactional(readOnly=true) List<String> getUserNames(final String searchString); @Override @Transactional(readOnly=true) UserDetail getUserDetail(final String userName); @Override @Transactional void disableOperatorRole(User user); @Override @Transactional boolean createUser(String userName, String password, boolean admin); @Override @Transactional boolean updateUser(UserDetail userDetail); @Override @Transactional boolean deactivateUser(UserDetail userDetail); @Autowired void setSesssionFactory(SessionFactory sessionFactory); @Autowired void setAuthoritiesService(StandardAuthoritiesService authoritiesService); @Autowired void setUserDao(UserDao userDao); @Autowired void setUserService(UserService userService); @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); void setPasswordEncoder(Object passwordEncoder);  }### Answer:
@Test public void testCreateOperator() { UserIndex userIndex = mock(UserIndex.class); when(userService.getOrCreateUserForUsernameAndPassword("operator", "password")).thenReturn(userIndex); boolean success = service.createUser("operator", "password", false); assertTrue("Expecting user to be created successfully", success); verify(userService).getOrCreateUserForUsernameAndPassword("operator", "password"); verify(userService, times(0)).enableAdminRoleForUser(isA(User.class), isA(Boolean.class)); }
@Test public void testCreateAdmin() { UserIndex userIndex = mock(UserIndex.class); UserRole role = mock(UserRole.class); Set<UserRole> roles = new HashSet<UserRole>(); roles.add(role); when(userService.getOrCreateUserForUsernameAndPassword("admin", "password")).thenReturn(userIndex); when(userIndex.getUser()).thenReturn(user); when(authoritiesService.getUserRoleForName(StandardAuthoritiesService.USER)).thenReturn(role); when(user.getRoles()).thenReturn(roles); boolean success = service.createUser("admin", "password", true); assertTrue("Expecting user to be created successfully", success); verify(userService).getOrCreateUserForUsernameAndPassword("admin", "password"); verify(userService).enableAdminRoleForUser(user, false); verify(userDao).saveOrUpdateUser(user); }