### Question:
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);  }### Answer:
@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))); }
@Test public void getBookWithUnknownIdShouldReturn404() throws Exception { when(bookService.getBookById(1L)).thenThrow(new BookNotFoundException("Book with id '1' not found")); this.mockMvc .perform(get("/api/books/1")) .andExpect(status().isNotFound()); }