### Question:
UserOperations { public GenericResponse changePassword(UserChangePasswordRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e != null) { if(request.getNewPassword().equals(request.getConfirmNewPassword())) { e.setPassword(encoder.encode(request.getNewPassword())); e = employeeRepo.save(e); response.setSuccess(true); response.setMessage("Password Changed Successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } else { throw new IdeaLabApiException(VALIDATION_ERROR, "New Passwords do not match"); } } else { throw new IdeaLabApiException(USER_NOT_FOUND); } } UserOperations(EmployeeRepo employeeRepo, BCryptPasswordEncoder encoder); DataResponse<BasicEmployee> getAllUsers(); GenericResponse userSignUp(EmployeeSignUpRequest request); GenericResponse deleteUser(Integer id); GenericResponse changePassword(UserChangePasswordRequest request); GenericResponse updateUser(EmployeeUpdateRequest request);  }### Answer:
@Test public void changePasswordSuccess() { UserChangePasswordRequest request = new UserChangePasswordRequest(); request.setUsername("testuser"); request.setNewPassword("New1"); request.setConfirmNewPassword("New1"); Employee e = new Employee(); e.setUsername("testuser"); e.setPassword("testpassword"); when(employeeRepo.findEmployeeByUsername(e.getUsername())).thenReturn(e); when(employeeRepo.save(e)).thenReturn(e); GenericResponse response = new GenericResponse(); response.setSuccess(true); response.setMessage("Password Changed Successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); GenericResponse opResponse = operations.changePassword(request); assert(opResponse.equals(response)); }
@Test(expected = IdeaLabApiException.class) public void changePasswordInvalidEmployee() { UserChangePasswordRequest request = new UserChangePasswordRequest(); request.setUsername("testuser"); request.setNewPassword("New1"); request.setConfirmNewPassword("New1"); when(employeeRepo.findEmployeeByUsername(anyString())).thenReturn(null); operations.changePassword(request); }
@Test(expected = IdeaLabApiException.class) public void changePasswordNewPasswordNoMatch() { UserChangePasswordRequest request = new UserChangePasswordRequest(); request.setUsername("testuser"); request.setNewPassword("New1"); request.setConfirmNewPassword("New2"); Employee e = new Employee(); e.setUsername("testuser"); e.setPassword("nonmatch"); when(employeeRepo.findEmployeeByUsername(e.getUsername())).thenReturn(e); operations.changePassword(request); }