### Question:
UserManager implements Serializable { public ResultCode cancelRegistration(int userId, String password) { UserPassword storedPassword = databaseModel.getUserPassword(userId); if (storedPassword == null) { return ResultCode.NO_SUCH_USER; } String passwordHash = calculatePasswordHash(password, storedPassword.getSalt()); if (storedPassword.getHash().equalsIgnoreCase(passwordHash) == false) { return ResultCode.INVALID_PASSWORD; } if (databaseModel.deleteUser(userId)) { return ResultCode.OK; } else { LOGGER.error("DB error: Failed to delete user with id={}.", userId); return ResultCode.DATABASE_ERROR; } } 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 testCancelRegistration() { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(storedPassword); Mockito.when(databaseModel.deleteUser(1)).thenReturn(true); ResultCode result = userManager.cancelRegistration(1, "password"); Assert.assertEquals(ResultCode.OK, result); Mockito.verify(databaseModel).deleteUser(1); }
@Test public void testCancelRegistrationUserDoesntExist() { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(null); ResultCode result = userManager.cancelRegistration(1, "password"); Assert.assertEquals(ResultCode.NO_SUCH_USER, result); Mockito.verify(databaseModel, Mockito.times(0)).deleteUser(1); }
@Test public void testCancelRegistrationWrongPassword() { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(storedPassword); ResultCode result = userManager.cancelRegistration(1, "wrong_password"); Assert.assertEquals(ResultCode.INVALID_PASSWORD, result); Mockito.verify(databaseModel, Mockito.times(0)).deleteUser(1); }