### Question:
TrainController { @CrossOrigin(origins = "*") @DeleteMapping(value = "/trains/{id}") public HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers) { boolean isDeleteSuccess = trainService.delete(id, headers); if (isDeleteSuccess) { return ok(new Response(1, "delete success", isDeleteSuccess)); } else { return ok(new Response(0, "there is no train according to id", null)); } }  @GetMapping(path = "/trains/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/trains") HttpEntity create(@RequestBody TrainType trainType, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/trains/{id}") HttpEntity retrieve(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PutMapping(value = "/trains") HttpEntity update(@RequestBody TrainType trainType, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @DeleteMapping(value = "/trains/{id}") HttpEntity delete(@PathVariable String id, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/trains") HttpEntity query(@RequestHeader HttpHeaders headers);  }### Answer:
@Test public void testDelete1() throws Exception { Mockito.when(trainService.delete(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(true); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/trainservice/trains/id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(new Response(1, "delete success", true), JSONObject.parseObject(result, Response.class)); }
@Test public void testDelete2() throws Exception { Mockito.when(trainService.delete(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(false); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/trainservice/trains/id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(new Response(0, "there is no train according to id", null), JSONObject.parseObject(result, Response.class)); }