@Test @Order(5) public void testResign() { given() .pathParam("id", 1) .when().delete("/{id}") .then() .statusCode(204); given() .pathParam("id", 1) .when().get("/{id}") .then() .statusCode(404); }
@DeleteMapping("/{id}") public ResponseEntity<Void> resign(@PathVariable long id) { if (employeeRepository.findById(id).isPresent()) { employeeRepository.deleteById(id); return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); } }
EmployeeController { @DeleteMapping("/{id}") public ResponseEntity<Void> resign(@PathVariable long id) { if (employeeRepository.findById(id).isPresent()) { employeeRepository.deleteById(id); return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); } } }
EmployeeController { @DeleteMapping("/{id}") public ResponseEntity<Void> resign(@PathVariable long id) { if (employeeRepository.findById(id).isPresent()) { employeeRepository.deleteById(id); return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); } } EmployeeController(EmployeeRepository employeeRepository); }
EmployeeController { @DeleteMapping("/{id}") public ResponseEntity<Void> resign(@PathVariable long id) { if (employeeRepository.findById(id).isPresent()) { employeeRepository.deleteById(id); return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); } } EmployeeController(EmployeeRepository employeeRepository); @GetMapping(value = "/all", produces = "application/json") Iterable<Employee> getAll(); @GetMapping("/{id}") Employee get(@PathVariable long id); @PostMapping @ResponseStatus(HttpStatus.CREATED) void register(@RequestParam("name") String name); @DeleteMapping("/{id}") ResponseEntity<Void> resign(@PathVariable long id); }
EmployeeController { @DeleteMapping("/{id}") public ResponseEntity<Void> resign(@PathVariable long id) { if (employeeRepository.findById(id).isPresent()) { employeeRepository.deleteById(id); return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); } } EmployeeController(EmployeeRepository employeeRepository); @GetMapping(value = "/all", produces = "application/json") Iterable<Employee> getAll(); @GetMapping("/{id}") Employee get(@PathVariable long id); @PostMapping @ResponseStatus(HttpStatus.CREATED) void register(@RequestParam("name") String name); @DeleteMapping("/{id}") ResponseEntity<Void> resign(@PathVariable long id);  }