@Test public void updateBookWithUnknownIdShouldReturn404() throws Exception { BookRequest bookRequest = new BookRequest(); bookRequest.setAuthor("Duke"); bookRequest.setIsbn("1337"); bookRequest.setTitle("Java 12"); when(bookService.updateBook(eq(42L), bookRequestArgumentCaptor.capture())) .thenThrow(new BookNotFoundException("The book with id '42' was not found")); this.mockMvc .perform(put("/api/books/42") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(bookRequest))) .andExpect(status().isNotFound()); }
@PutMapping("/{id}") public ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest) { return ResponseEntity.ok(bookService.updateBook(id, bookRequest)); }
BookController { @PutMapping("/{id}") public ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest) { return ResponseEntity.ok(bookService.updateBook(id, bookRequest)); } }
BookController { @PutMapping("/{id}") public ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest) { return ResponseEntity.ok(bookService.updateBook(id, bookRequest)); }  }
BookController { @PutMapping("/{id}") public ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest) { return ResponseEntity.ok(bookService.updateBook(id, bookRequest)); }  @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 { @PutMapping("/{id}") public ResponseEntity<Book> updateBook(@PathVariable("id") Long id, @Valid @RequestBody BookRequest bookRequest) { return ResponseEntity.ok(bookService.updateBook(id, bookRequest)); }  @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);  }