@Test public void getBookWithIdOneShouldReturnABook() throws Exception { when(bookService.getBookById(1L)).thenReturn(createBook(1L, "Java 11", "Duke", "1337")); this.mockMvc .perform(get("/api/books/1")) .andExpect(status().isOk()) .andExpect(content().contentType("application/json")) .andExpect(jsonPath("$.title", is("Java 11"))) .andExpect(jsonPath("$.author", is("Duke"))) .andExpect(jsonPath("$.isbn", is("1337"))) .andExpect(jsonPath("$.id", is(1))); }
@GetMapping("/{id}") public ResponseEntity<Book> getBookById(@PathVariable("id") Long id) { return ResponseEntity.ok(bookService.getBookById(id)); }
BookController { @GetMapping("/{id}") public ResponseEntity<Book> getBookById(@PathVariable("id") Long id) { return ResponseEntity.ok(bookService.getBookById(id)); } }
BookController { @GetMapping("/{id}") public ResponseEntity<Book> getBookById(@PathVariable("id") Long id) { return ResponseEntity.ok(bookService.getBookById(id)); }  }
BookController { @GetMapping("/{id}") public ResponseEntity<Book> getBookById(@PathVariable("id") Long id) { return ResponseEntity.ok(bookService.getBookById(id)); }  @PostMapping ResponseEntity<Void> createNewBook(@Valid @RequestBody BookRequest bookRequest, UriComponentsBuilder uriComponentsBuilder); @GetMapping ResponseEntity<List<Book>> getAllBooks(); @GetMapping("/{id}") ResponseEntity<Book> getBookById(@PathVariable("id") Long id); @PutMapping("/{id}") ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest); @DeleteMapping("/{id}") ResponseEntity<Void> deleteBook(@PathVariable("id") Long id); }
BookController { @GetMapping("/{id}") public ResponseEntity<Book> getBookById(@PathVariable("id") Long id) { return ResponseEntity.ok(bookService.getBookById(id)); }  @PostMapping ResponseEntity<Void> createNewBook(@Valid @RequestBody BookRequest bookRequest, UriComponentsBuilder uriComponentsBuilder); @GetMapping ResponseEntity<List<Book>> getAllBooks(); @GetMapping("/{id}") ResponseEntity<Book> getBookById(@PathVariable("id") Long id); @PutMapping("/{id}") ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest); @DeleteMapping("/{id}") ResponseEntity<Void> deleteBook(@PathVariable("id") Long id);  }