@Test public void shouldReturnListOfBooks() throws Exception { when(bookService.findAll()).thenReturn(Arrays.asList( new Book("123", "Spring 5 Recipes", "Marten Deinum", "Josh Long"), new Book("321", "Pro Spring MVC", "Marten Deinum", "Colin Yates"))); mockMvc.perform(get("/books.html")) .andExpect(status().isOk()) .andExpect(view().name("books/list")) .andExpect(model().attribute("books", Matchers.hasSize(2))); }
@GetMapping(value = "/books.html", params = "isbn") public String get(@RequestParam("isbn") String isbn, Model model) { bookService.find(isbn) .ifPresent(book -> model.addAttribute("book", book)); return "books/details"; }
BookController { @GetMapping(value = "/books.html", params = "isbn") public String get(@RequestParam("isbn") String isbn, Model model) { bookService.find(isbn) .ifPresent(book -> model.addAttribute("book", book)); return "books/details"; } }
BookController { @GetMapping(value = "/books.html", params = "isbn") public String get(@RequestParam("isbn") String isbn, Model model) { bookService.find(isbn) .ifPresent(book -> model.addAttribute("book", book)); return "books/details"; } BookController(BookService bookService); }
BookController { @GetMapping(value = "/books.html", params = "isbn") public String get(@RequestParam("isbn") String isbn, Model model) { bookService.find(isbn) .ifPresent(book -> model.addAttribute("book", book)); return "books/details"; } BookController(BookService bookService); @GetMapping("/books.html") String all(Model model); @GetMapping(value = "/books.html", params = "isbn") String get(@RequestParam("isbn") String isbn, Model model); @PostMapping("/books") Book create(@ModelAttribute Book book); @GetMapping("/books/404") ResponseEntity notFound(); @GetMapping("/books/400") ResponseEntity foo(); @GetMapping("/books/500") void error(); }
BookController { @GetMapping(value = "/books.html", params = "isbn") public String get(@RequestParam("isbn") String isbn, Model model) { bookService.find(isbn) .ifPresent(book -> model.addAttribute("book", book)); return "books/details"; } BookController(BookService bookService); @GetMapping("/books.html") String all(Model model); @GetMapping(value = "/books.html", params = "isbn") String get(@RequestParam("isbn") String isbn, Model model); @PostMapping("/books") Book create(@ModelAttribute Book book); @GetMapping("/books/404") ResponseEntity notFound(); @GetMapping("/books/400") ResponseEntity foo(); @GetMapping("/books/500") void error();  }