@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("")); }
@Test public void shouldPassANotificationToTheViewThatBookWasRecommended() { BookService bookService = mock(BookService.class); Book book = getBook(); when(bookService.getBookByID(0)).thenReturn(book); BookViewController bookViewController = new BookViewController(bookService); RedirectView viewBook = bookViewController.recommend(0); String actualNotification = viewBook.getUrl(); assertThat( actualNotification, is( "/viewbook?bookId=" + book.getId() + "¬ification=" + BookViewController.RECOMMENDED_SUCCESFULLY)); }