@Test public void shouldCreateUser() throws Exception { final Book savedBook = stubServiceToReturnStoredBook(); final Book book = UserUtil.createBook(); Book returnedBook = bookController.saveBook(book); verify(bookService, times(1)).saveBook(book); assertEquals("Returned book should come from the service", savedBook, returnedBook); }
@RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) public Book saveBook(@RequestBody @Valid final Book book) { LOGGER.debug("Received request to create the {}", book); return bookService.saveBook(book); }
BookController { @RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) public Book saveBook(@RequestBody @Valid final Book book) { LOGGER.debug("Received request to create the {}", book); return bookService.saveBook(book); } }
BookController { @RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) public Book saveBook(@RequestBody @Valid final Book book) { LOGGER.debug("Received request to create the {}", book); return bookService.saveBook(book); } @Autowired  BookController(final BookService bookService); }
BookController { @RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) public Book saveBook(@RequestBody @Valid final Book book) { LOGGER.debug("Received request to create the {}", book); return bookService.saveBook(book); } @Autowired  BookController(final BookService bookService); @RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) Book saveBook(@RequestBody @Valid final Book book); @ApiOperation(value = "Retrieve a list of books.", responseContainer = "List") @RequestMapping(value = "/books", method = RequestMethod.GET, produces = {"application/json"}) List<Book> listBooks(); @RequestMapping(value = "/books/{id}", method = RequestMethod.GET, produces = {"application/json"}) @ResponseBody Book singleBook(@PathVariable Long id); @RequestMapping(value = "/books/{id}", method = RequestMethod.DELETE) void deleteBook(@PathVariable Long id); @ExceptionHandler @ResponseStatus(HttpStatus.CONFLICT) String handleUserAlreadyExistsException(BookAlreadyExistsException e); }
BookController { @RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) public Book saveBook(@RequestBody @Valid final Book book) { LOGGER.debug("Received request to create the {}", book); return bookService.saveBook(book); } @Autowired  BookController(final BookService bookService); @RequestMapping(value = "/books", method = RequestMethod.POST, consumes = {"application/json"}) Book saveBook(@RequestBody @Valid final Book book); @ApiOperation(value = "Retrieve a list of books.", responseContainer = "List") @RequestMapping(value = "/books", method = RequestMethod.GET, produces = {"application/json"}) List<Book> listBooks(); @RequestMapping(value = "/books/{id}", method = RequestMethod.GET, produces = {"application/json"}) @ResponseBody Book singleBook(@PathVariable Long id); @RequestMapping(value = "/books/{id}", method = RequestMethod.DELETE) void deleteBook(@PathVariable Long id); @ExceptionHandler @ResponseStatus(HttpStatus.CONFLICT) String handleUserAlreadyExistsException(BookAlreadyExistsException e);  }