### Question:
UserManager implements Serializable { public ResultCode resendRegistrationEmail(String address) { User user = databaseModel.getUserByEmail(address); if (user == null) { return ResultCode.NO_SUCH_USER; } if (user.isRegistrationConfirmed()) { return ResultCode.REGISTRATION_ALREADY_CONFIRMED; } if (emailSender.sendRegistrationEmail(address, user.getName(), user.getId(), user.getRegistrationControlCode())) { return ResultCode.OK; } else { LOGGER.error("Email error: Failed to re-send registration email to user with id={}.", user.getId()); 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 testResendRegistrationEmail() { Mockito.when(databaseModel.getUserByEmail("carl@example.com")).thenReturn(userWithUnfinishedRegistration); Mockito.when(emailSender.sendRegistrationEmail("carl@example.com", "Carl", 2, userWithUnfinishedRegistration.getRegistrationControlCode())).thenReturn(true); ResultCode result = userManager.resendRegistrationEmail("carl@example.com"); Assert.assertEquals(ResultCode.OK, result); Mockito.verify(emailSender).sendRegistrationEmail("carl@example.com", "Carl", 2, userWithUnfinishedRegistration.getRegistrationControlCode()); }
@Test public void testResendRegistrationEmailFailedToSendEmail() { Mockito.when(databaseModel.getUserByEmail("carl@example.com")).thenReturn(userWithUnfinishedRegistration); Mockito.when(emailSender.sendRegistrationEmail("carl@example.com", "Carl", 2, userWithUnfinishedRegistration.getRegistrationControlCode())).thenReturn(false); ResultCode result = userManager.resendRegistrationEmail("carl@example.com"); Assert.assertEquals(ResultCode.FAILED_TO_SEND_EMAIL, result); }
@Test public void testResendRegistrationEmailNoSuchUser() { Mockito.when(databaseModel.getUserByEmail("bender@example.com")).thenReturn(null); ResultCode result = userManager.resendRegistrationEmail("bender@example.com"); Assert.assertEquals(ResultCode.NO_SUCH_USER, result); }
@Test public void testResendRegistrationEmailRegistrationAlreadyConfirmed() { Mockito.when(databaseModel.getUserByEmail("john@example.com")).thenReturn(storedUser); ResultCode result = userManager.resendRegistrationEmail("john@example.com"); Assert.assertEquals(ResultCode.REGISTRATION_ALREADY_CONFIRMED, result); }