### Question:
UserManager implements Serializable { public ResultCode changePassword(int userId, String oldPassword, String newPassword) { if (!isPasswordValid(userId, oldPassword)) { return ResultCode.INVALID_PASSWORD; } UserPassword userPassword = createUserPassword(newPassword); boolean ok = databaseModel.setUserPassword(userId, userPassword); if (!ok) { LOGGER.error("DB error: Failed to set password for user with id={}.", userId); return ResultCode.DATABASE_ERROR; } return ResultCode.OK; } 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 testChangePassword() throws Exception { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(storedPassword); Mockito.when(databaseModel.setUserPassword(Mockito.eq(1), Mockito.any(UserPassword.class))).thenReturn(true); ResultCode result = userManager.changePassword(1, "password", "new_password"); Assert.assertEquals(ResultCode.OK, result); ArgumentCaptor<UserPassword> passwordCaptor = ArgumentCaptor.forClass(UserPassword.class); Mockito.verify(databaseModel).setUserPassword(Mockito.eq(1), passwordCaptor.capture()); UserPassword newPassword = passwordCaptor.getValue(); assertPasswordData("new_password", newPassword); }
@Test public void testChangePasswordWrongPassword() { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(storedPassword); ResultCode result = userManager.changePassword(1, "wrong_old_password", "new_password"); Assert.assertEquals(ResultCode.INVALID_PASSWORD, result); Mockito.verify(databaseModel, Mockito.never()).setUserPassword(Mockito.anyInt(), Mockito.any(UserPassword.class)); }