@Test @Order(3) public void testFindByIdNotFound() { given() .pathParam("id", 99L) .when().get("/{id}") .then() .statusCode(404); }
@GetMapping("/{id}") public Employee get(@PathVariable long id) { return employeeRepository.findById(id).orElseThrow(() -> new NotFoundException("employee id = " + id + " is not found")); }
EmployeeController { @GetMapping("/{id}") public Employee get(@PathVariable long id) { return employeeRepository.findById(id).orElseThrow(() -> new NotFoundException("employee id = " + id + " is not found")); } }
EmployeeController { @GetMapping("/{id}") public Employee get(@PathVariable long id) { return employeeRepository.findById(id).orElseThrow(() -> new NotFoundException("employee id = " + id + " is not found")); } EmployeeController(EmployeeRepository employeeRepository); }
EmployeeController { @GetMapping("/{id}") public Employee get(@PathVariable long id) { return employeeRepository.findById(id).orElseThrow(() -> new NotFoundException("employee id = " + id + " is not found")); } 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 { @GetMapping("/{id}") public Employee get(@PathVariable long id) { return employeeRepository.findById(id).orElseThrow(() -> new NotFoundException("employee id = " + id + " is not found")); } 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);  }