コード例 #1
0
  @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(""));
  }
コード例 #2
0
  @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()
                + "&notification="
                + BookViewController.RECOMMENDED_SUCCESFULLY));
  }