### Question:
UserOperations { public GenericResponse updateUser(EmployeeUpdateRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e == null){ throw new IdeaLabApiException(USER_NOT_FOUND); } String requestRole = request.getRole(); e.setRole(EmployeeRole.fromValue(requestRole)); employeeRepo.save(e); response.setSuccess(true); response.setMessage("Employee role updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } 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 userUpdate() { EmployeeUpdateRequest request = new EmployeeUpdateRequest(); request.setUsername("username"); request.setRole("ADMIN"); Employee e = new Employee(); e.setUsername("username"); e.setRole(EmployeeRole.STAFF); when(employeeRepo.findEmployeeByUsername(request.getUsername())).thenReturn(e); e.setRole(EmployeeRole.ADMIN); when(employeeRepo.save(e)).thenReturn(e); GenericResponse response = operations.updateUser(request); verify(employeeRepo, times(1)).findEmployeeByUsername(request.getUsername()); verify(employeeRepo, times(1)).save(e); assertTrue(response.isSuccess() == true); assertTrue(response.getMessage().equalsIgnoreCase("Employee role updated successfully")); }
@Test(expected = IdeaLabApiException.class) public void userUpdate_NoRole() { EmployeeUpdateRequest request = new EmployeeUpdateRequest(); request.setUsername("username"); GenericResponse response = operations.updateUser(request); }
@Test(expected = IdeaLabApiException.class) public void userUpdate_NotValidRole() { EmployeeUpdateRequest request = new EmployeeUpdateRequest(); request.setUsername("username"); request.setRole("NOT_VALID"); GenericResponse response = operations.updateUser(request); }
@Test(expected = IdeaLabApiException.class) public void userUpdate_NoUsername() { EmployeeUpdateRequest request = new EmployeeUpdateRequest(); request.setRole("ADMIN"); GenericResponse response = operations.updateUser(request); }
@Test(expected = IdeaLabApiException.class) public void userUpdate_NotValidUsername() { EmployeeUpdateRequest request = new EmployeeUpdateRequest(); request.setUsername("username"); request.setRole("ADMIN"); Employee e = new Employee(); e.setUsername("username"); e.setRole(EmployeeRole.STAFF); when(employeeRepo.findEmployeeByUsername(request.getUsername())).thenReturn(null); GenericResponse response = operations.updateUser(request); }