### Question:
UserManager implements Serializable { public boolean isPasswordValid(int userId, String password) { UserPassword storedPassword = databaseModel.getUserPassword(userId); if (storedPassword == null) { return false; } String hash = calculatePasswordHash(password, storedPassword.getSalt()); return storedPassword.getHash().equalsIgnoreCase(hash); } 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 testIsPasswordValidTrue() { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(storedPassword); boolean result = userManager.isPasswordValid(1, "password"); Assert.assertEquals(true, result); }
@Test public void testIsPasswordValidFalse() { Mockito.when(databaseModel.getUserPassword(1)).thenReturn(storedPassword); boolean result = userManager.isPasswordValid(1, "wrong_password"); Assert.assertEquals(false, result); }
@Test public void testIsPasswordValidNoSuchUser() { Mockito.when(databaseModel.getUserPassword(2)).thenReturn(null); boolean result = userManager.isPasswordValid(2, "password"); Assert.assertEquals(false, result); }