@Test public void shouldReturn404WhenBookNotFound() throws Exception { when(bookService.find(anyString())).thenReturn(Optional.empty()); mockMvc.perform(get("/books/123")) .andExpect(status().isNotFound()); }
@GetMapping("/{isbn}") public ResponseEntity<Book> get(@PathVariable("isbn") String isbn) { return bookService.find(isbn) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); }
BookController { @GetMapping("/{isbn}") public ResponseEntity<Book> get(@PathVariable("isbn") String isbn) { return bookService.find(isbn) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } }
BookController { @GetMapping("/{isbn}") public ResponseEntity<Book> get(@PathVariable("isbn") String isbn) { return bookService.find(isbn) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } BookController(BookService bookService); }
BookController { @GetMapping("/{isbn}") public ResponseEntity<Book> get(@PathVariable("isbn") String isbn) { return bookService.find(isbn) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } BookController(BookService bookService); @GetMapping @PermitAll Iterable<Book> all(); @GetMapping("/{isbn}") ResponseEntity<Book> get(@PathVariable("isbn") String isbn); @PostMapping ResponseEntity<Book> create(@RequestBody Book book,
                                     UriComponentsBuilder uriBuilder); }
BookController { @GetMapping("/{isbn}") public ResponseEntity<Book> get(@PathVariable("isbn") String isbn) { return bookService.find(isbn) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } BookController(BookService bookService); @GetMapping @PermitAll Iterable<Book> all(); @GetMapping("/{isbn}") ResponseEntity<Book> get(@PathVariable("isbn") String isbn); @PostMapping ResponseEntity<Book> create(@RequestBody Book book,
                                     UriComponentsBuilder uriBuilder);  }