@Test @Order(1) public void testAll() { List<Employee> employees = given() .contentType(ContentType.JSON) .when().get("/all").as(new TypeRef<List<Employee>>() {}); assertThat(employees, hasSize(5)); assertThat(employees.get(0).getId(), equalTo(1L)); assertThat(employees.get(0).getName(), equalTo("Penny")); assertThat(employees.get(1).getId(), equalTo(2L)); assertThat(employees.get(1).getName(), equalTo("Sheldon")); assertThat(employees.get(2).getId(), equalTo(3L)); assertThat(employees.get(2).getName(), equalTo("Amy")); assertThat(employees.get(3).getId(), equalTo(4L)); assertThat(employees.get(3).getName(), equalTo("Leonard")); assertThat(employees.get(4).getId(), equalTo(5L)); assertThat(employees.get(4).getName(), equalTo("Bernadette")); }
@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);  }