### Question:
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);  }### Answer:
@Test public void updateBookWithKnownIdShouldUpdateTheBook() throws Exception { BookRequest bookRequest = new BookRequest(); bookRequest.setAuthor("Duke"); bookRequest.setIsbn("1337"); bookRequest.setTitle("Java 12"); when(bookService.updateBook(eq(1L), bookRequestArgumentCaptor.capture())) .thenReturn(createBook(1L, "Java 12", "Duke", "1337")); this.mockMvc .perform(put("/api/books/1") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(bookRequest))) .andExpect(status().isOk()) .andExpect(content().contentType("application/json")) .andExpect(jsonPath("$.title", is("Java 12"))) .andExpect(jsonPath("$.author", is("Duke"))) .andExpect(jsonPath("$.isbn", is("1337"))) .andExpect(jsonPath("$.id", is(1))); assertThat(bookRequestArgumentCaptor.getValue().getAuthor(), is("Duke")); assertThat(bookRequestArgumentCaptor.getValue().getIsbn(), is("1337")); assertThat(bookRequestArgumentCaptor.getValue().getTitle(), is("Java 12")); }
@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()); }