### Question:
UserController { @DeleteMapping("/{id}") public ResponseEntity<?> deleteUser(@PathVariable("id") Integer id) { GenericResponse response = userOperations.deleteUser(id); return new ResponseEntity<>(response, response.getHttpStatus()); } UserController(UserOperations userOperations); @PostMapping("/sign-up") ResponseEntity<?> signUp(@RequestBody EmployeeSignUpRequest user); @PutMapping("/update") ResponseEntity<?> updateUser(@RequestBody EmployeeUpdateRequest request); @DeleteMapping("/{id}") ResponseEntity<?> deleteUser(@PathVariable("id") Integer id); @PostMapping("/password") ResponseEntity<?> changePassword(@RequestBody UserChangePasswordRequest request); @GetMapping() ResponseEntity<?> getUsers();  }### Answer:
@Test public void userDelete() throws Exception { GenericResponse genericResponse = new GenericResponse(); genericResponse.setSuccess(true); genericResponse.setMessage("Employee Deleted Successfully"); genericResponse.setHttpStatus(HttpStatus.ACCEPTED); when(operations.deleteUser(1)).thenReturn(genericResponse); String returnJson = mockMvc.perform(delete("/users/1") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is2xxSuccessful()) .andReturn().getResponse().getContentAsString(); GenericResponse returnedResponse = stringToGenericResponse(returnJson); assert (returnedResponse.equals(genericResponse)); }
@Test public void userDeleteFailNonUser() throws Exception { GenericResponse genericResponse = new GenericResponse(); genericResponse.setSuccess(false); genericResponse.setMessage("Employee ID is not valid"); genericResponse.setHttpStatus(HttpStatus.BAD_REQUEST); when(operations.deleteUser(1)).thenReturn(genericResponse); String returnJson = mockMvc.perform(delete("/users/1") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is4xxClientError()) .andReturn().getResponse().getContentAsString(); GenericResponse returnedResponse = stringToGenericResponse(returnJson); assert (returnedResponse.equals(genericResponse)); }
@Test public void userDeleteFail() throws Exception { GenericResponse genericResponse = new GenericResponse(); genericResponse.setSuccess(false); genericResponse.setMessage("Employee Could Not Be Deleted"); genericResponse.setHttpStatus(HttpStatus.BAD_REQUEST); when(operations.deleteUser(1)).thenReturn(genericResponse); String returnJson = mockMvc.perform(delete("/users/1") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is4xxClientError()) .andReturn().getResponse().getContentAsString(); GenericResponse returnedResponse = stringToGenericResponse(returnJson); assert (returnedResponse.equals(genericResponse)); }