### Question:
UserOperations { public GenericResponse deleteUser(Integer id) { GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeById(id); if(e != null) { try { employeeRepo.deleteById(id); response.setSuccess(true); response.setMessage("Employee Deleted Successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); } catch (Exception ex) { ex.printStackTrace(); response.setSuccess(false); response.setMessage("Employee Could Not Be Deleted"); response.setHttpStatus(HttpStatus.BAD_REQUEST); } } else { response.setSuccess(false); response.setMessage("Employee ID is not valid"); response.setHttpStatus(HttpStatus.BAD_REQUEST); } 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 userDelete() { Employee e = new Employee(); e.setId(1); when(employeeRepo.findEmployeeById(e.getId())).thenReturn(e); doNothing().when(employeeRepo).deleteById(e.getId()); GenericResponse response = operations.deleteUser(e.getId()); assertTrue(response.isSuccess() == true); assertTrue(response.getMessage().equalsIgnoreCase("Employee Deleted Successfully")); }
@Test public void userDeleteFailNonEmployee() { when(employeeRepo.findEmployeeById(1)).thenReturn(null); GenericResponse response = operations.deleteUser(1); assertTrue(response.isSuccess() == false); assertTrue(response.getMessage().equalsIgnoreCase("Employee ID is not valid")); }
@Test public void userDeleteFail() { Employee e = new Employee(); e.setId(1); when(employeeRepo.findEmployeeById(e.getId())).thenReturn(e); doThrow(new RuntimeException()).when(employeeRepo).deleteById(1); GenericResponse response = operations.deleteUser(1); assertTrue(response.isSuccess() == false); assertTrue(response.getMessage().equalsIgnoreCase("Employee Could Not Be Deleted")); }