コード例 #1
0
  @Test
  public void shouldPrintBookInformationWhenListDetailsIsCalled() {
    PrintStream printStream = mock(PrintStream.class);
    Book book = new Book("Dracula", "Bram Stoker", "1875", printStream);

    book.listDetails();

    verify(printStream).println("Dracula\tBram Stoker\t1875");
  }
コード例 #2
0
  public static void main(String[] args) {
    System.out.println("Hello, world!");

    Book.generateBookList();
    Movie.generateMovieList();
    User.generateUserList();

    String introduce = "Welcome!";
    String[] mainMenuOptions = {"List Books", "List Movies", "Login", "User Detail"};
    Listener[] mainMenuListeners = {
      new ListBooksListener(),
      new ListMovieListener(),
      new LoginListener(),
      new UserDetailListener()
    };
    Menu.getMenuStack().push(new Menu(introduce, mainMenuOptions, mainMenuListeners));

    while (true) {
      if (Menu.getMenuStack().empty()) {
        break;
      }
      Menu currentMenu = Menu.getMenuStack().peek();

      currentMenu.printMenu();
      Scanner stdin = new Scanner(System.in);

      System.out.println();
      System.out.print("input: ");
      String input = stdin.nextLine();

      currentMenu.checkInput(input);
    }
  }
コード例 #3
0
  public void call() {
    String introduce = "Choose a book for further options.";
    ArrayList<Book> bookList = Book.getBookList();
    String[] menuOptions = new String[bookList.size()];
    Listener[] menuListeners = new Listener[bookList.size()];
    for (int i = 0; i < bookList.size(); i++) {
      menuOptions[i] = bookList.get(i).getTitle();
      menuListeners[i] = new BookDetailListener(bookList.get(i));
    }

    Menu listBookMenu = new Menu(introduce, menuOptions, menuListeners);
    Menu.getMenuStack().push(listBookMenu);
  }
コード例 #4
0
 @Test
 public void testToString() {
   String expected = "\"The Death and Life of Great American Cities\" by Jane Jacobs [1961]";
   assertEquals(expected, book.toString());
 }
コード例 #5
0
 private static void whoHasBooks() {
   for (Book book : library.getLoanedBooks()) {
     System.out.println(book + " : " + book.loanedTo());
   }
 }