private ModelAndView bookPageModelAndView(String ID, boolean isValidID) throws IOException { BookService bookService = mock(BookService.class); Book book = (isValidID) ? getBook() : null; when(bookService.getBookByID(Integer.parseInt(ID))).thenReturn(book); BookViewController bookViewController = new BookViewController(bookService); return bookViewController.viewBook(ID, ""); }
@Test public void shouldHaveEmptyNotificationWhenUserViewsBookForFirstTime() { BookService bookService = mock(BookService.class); Book book = getBook(); when(bookService.getBookByID(book.getId())).thenReturn(book); BookViewController bookViewController = new BookViewController(bookService); ModelAndView viewBook = bookViewController.viewBook(Integer.toString(book.getId()), ""); String actualNotification = (String) viewBook.getModel().get("notification"); assertThat(actualNotification, is("")); }