### Question:
UserManager implements Serializable { public ResultCode registerUserManually(String email, String name, int rank) { ResultCode checkResult = checkRegistrationPreconditions(email, name); if (checkResult != ResultCode.OK) { return checkResult; } String controlCode = generateRandomMD5Hash(); UserPassword userPassword = createUserPassword(""); User newUser = new User(-1, name, email, controlCode, false, userPassword, rank); int newUserId = databaseModel.addUser(newUser); if (newUserId < 0) { LOGGER.error("DB error: Failed to add user: name={}, email={}.", name, email); return ResultCode.DATABASE_ERROR; } User registrator = sessionModel.getCurrentUser(); if (emailSender.sendManualRegistrationEmail(email, name, newUserId, controlCode, registrator)) { return ResultCode.OK; } else { LOGGER.error("Email error: Failed to send manual registration email to user with id={}.", newUserId); return ResultCode.FAILED_TO_SEND_EMAIL; } } UserManager(); ResultCode cancelPasswordResetTokens(int userId); ResultCode cancelRegistration(int userId, String password); ResultCode changePassword(int userId, String oldPassword, String newPassword); PasswordCheckResult checkPassword(String password, String passwordConfirmation); ResultCode confirmManualRegistration(String email, String registrationControlCode, String password); ResultCode confirmRegistration(String email, String registrationControlCode); ResultCode createPasswordResetToken(String email); User getCurrentUser(); int getRegisteredUserCount(Date since); boolean isPasswordResetTokenValid(String email, String tokenKey); boolean isPasswordValid(int userId, String password); ResultCode logIn(String userNameOrEmail, String password, String usersIp); User loginOrRegisterWithSocialAccount(SocialAccountDetails details, String usersIp); ResultCode logInWithoutPassword(String userNameOrEmail); void logOut(); ResultCode registerUser(String email, String name, String password, boolean registrationConfirmed); ResultCode registerUserManually(String email, String name, int rank); ResultCode resendRegistrationEmail(String address); ResultCode resetPassword(String userEmail, String tokenKey, String newPassword); boolean sendTestingEmail(EmailType emailType, String address);  }### Answer:
@Test public void testRegisterUserManually() throws Exception { Mockito.when(databaseModel.isEmailRegistered("carl@example.com")).thenReturn(false); Mockito.when(databaseModel.isUserNameRegistered("Carl")).thenReturn(false); Mockito.when(databaseModel.addUser(Mockito.notNull(User.class))).thenReturn(2); Mockito.when( emailSender.sendManualRegistrationEmail(Mockito.eq("carl@example.com"), Mockito.eq("Carl"), Mockito.eq(2), Mockito.notNull(String.class), Mockito.any(User.class))) .thenReturn(true); User registrator = storedUser; Mockito.when(sessionModel.getCurrentUser()).thenReturn(registrator); ResultCode result = userManager.registerUserManually("carl@example.com", "Carl", UserRanks.NORMAL_USER); Assert.assertEquals(ResultCode.OK, result); ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class); Mockito.verify(databaseModel).addUser(userCaptor.capture()); User addedUser = userCaptor.getValue(); Assert.assertEquals(-1, addedUser.getId()); Assert.assertEquals("carl@example.com", addedUser.getEmail()); Assert.assertEquals("Carl", addedUser.getName()); Assert.assertEquals(false, addedUser.isRegistrationConfirmed()); assertPasswordData("", addedUser.getPassword()); Assert.assertEquals(UserRanks.NORMAL_USER, addedUser.getRank()); Mockito.verify(emailSender).sendManualRegistrationEmail("carl@example.com", "Carl", 2, addedUser.getRegistrationControlCode(), registrator); }