private Library buildMockLibraryWithSetBookAmounts(
     int numberOfBooksAvailable, int numberOfBooksCheckedOut) {
   library = mock(Library.class);
   when(library.numberOfBooksInLibrary()).thenReturn(numberOfBooksAvailable);
   when(library.numberOfBooksCheckedOut()).thenReturn(numberOfBooksCheckedOut);
   for (int i = 0; i < numberOfBooksAvailable; i++) {
     when(library.bookIsAvailable(i)).thenReturn(true);
   }
   for (int i = 0; i < numberOfBooksCheckedOut; i++) {
     when(library.bookIsCheckedOut(i)).thenReturn(true);
   }
   return library;
 }
 @Test
 public void shouldDisplayListOfBooksPresentInTheLibrary() {
   List<Book> listOfBooks = new ArrayList<Book>();
   Book book1 = new Book("Java design patterns", "pankaj", 1887);
   Book book2 = new Book("Head First Java", "Bert", 1991);
   listOfBooks.add(book1);
   listOfBooks.add(book2);
   Library library = new Library(listOfBooks);
   Console console = mock(Console.class);
   MainMenuOption listBooksoption = new ListBooksOption(library, console);
   listBooksoption.doOperation();
   verify(console).display(library.toString());
 }
  @Test
  public void testWarnsUserIfNoBooksAreAvailable() {
    when(library.numberOfBooksInLibrary()).thenReturn(0);

    checkoutBookMenuOperation.execute(library, console);
    verify(console).printMessage("There are no books available for checkout");
  }
Esempio n. 4
0
 public void showDetailsOfMovie(Library movies) {
   ArrayList<LibraryItem> coll = movies.ListAvailableBooks();
   System.out.format("%-25s%35s%35s%35s\n", "Name", "Director", "Years", "Rating");
   console.display(
       "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
   for (LibraryItem movie : coll) {
     System.out.println(movie);
   }
 }
Esempio n. 5
0
 public void showDetailsOfBook(Library collection) {
   ArrayList<LibraryItem> coll = collection.ListAvailableBooks();
   console.format("%-25s%25s%55s\n", "Name", "Author", "Years");
   console.display(
       "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
   for (LibraryItem book : coll) {
     System.out.println(book);
   }
 }
 private static void returnBook() {
   printLoanedBooks();
   System.out.println("\nEnter the number of the book to be returned: ");
   int bookIndex = keyboard.nextInt();
   try {
     library.getLoanedBooks().get(bookIndex).returnStock();
     System.out.println("Thank you for returning the book.");
   } catch (StockNotOutException e) {
     System.out.println("That is not a valid book to return");
   }
 }
 private static void checkoutMovie() {
   printAvailableMovies();
   System.out.println("Enter the number of the movie you would like to check out: ");
   int movieIndex = keyboard.nextInt();
   try {
     library.getAvailableMovies().get(movieIndex).checkOut(currentUser);
     System.out.println("Thank you! Enjoy the movie");
   } catch (StockNotAvailableException e) {
     System.out.println("That movie is not available");
   } catch (InvalidLoginException e) {
     System.out.println("Library number and password do not match");
   }
 }
 @Test
 public void testListBooksDetails() {
   Session session = Session.createTestSession();
   session.listItems(Library.createBookTestLibrary(), "");
   assertThat(
       session
           .history(-2)
           .contains(String.format(Constants.bookFormatString, "Book 1", "Author 1", 1337, "0")),
       is(true));
   assertThat(
       session
           .history(-2)
           .contains(String.format(Constants.bookFormatString, "Book 2", "Author 2", 1976, "1")),
       is(true));
 }
  private static void setupLibrary() {
    library = new Library();

    library.add(new Book("Pride and Prejudice", "Jane Austen", 1813));
    library.add(new Book("To Kill a Mockingbird", "Harper Lee", 1960));
    library.add(new Book("The Great Gatsby", "F. Scott Fitzgerald", 1922));
    library.add(new Book("Frankenstein", "Mary Shelley", 1818));

    library.add(new Movie("The Godfather", 1972, "Francis Ford Coppola", 9));
    library.add(new Movie("The Shawshank Redemption", 1994, "Frank Darabont", 10));
    library.add(new Movie("Sharktopus", 2006, "Declan O'Brien", 1));
    library.add(new Movie("Scooby Doo", 2002, "Raja Gosnell", 0));

    UserRegistry registry = UserRegistry.getInstance();
    User user = new User("123-4567", "password");
    user.setEmail("test@localhost");
    user.setPhone("+44 122 1111 444");
    user.setName("Joe Bloggs");
    registry.addUser(user);
    registry.addUser((new User("111-1111", "password", true)));
  }
 private static void printAvailableMovies() {
   System.out.println("Available Movies: \n");
   printList(library.getAvailableMovies());
 }
 private static void printLoanedBooks() {
   System.out.println("Loaned Books:\n");
   printList(library.getLoanedBooks());
 }
 private static void whoHasBooks() {
   for (Book book : library.getLoanedBooks()) {
     System.out.println(book + " : " + book.loanedTo());
   }
 }
 private static void whoHasMovies() {
   for (Movie movie : library.getLoanedMovies()) {
     System.out.println(movie + " : " + movie.loanedTo());
   }
 }
 @Test
 public void testAvailableBookListPrintedOnExecute() {
   checkoutBookMenuOperation.execute(library, console);
   verify(console).printLibraryItemList(library.availableBooks());
 }