public void testGetUnavailableBooks() { setup(); addItems(); assertEquals(0, myLibrary.getUnavailableBooks().size()); myLibrary.checkOut(b1, p1); ArrayList<Book> testBooks = myLibrary.getUnavailableBooks(); assertEquals(1, testBooks.size()); assertEquals(0, testBooks.indexOf(b1)); myLibrary.checkOut(b2, p2); testBooks = myLibrary.getUnavailableBooks(); assertEquals(2, testBooks.size()); assertEquals(1, testBooks.indexOf(b2)); }
public List<Book> read() { List<Book> books = bookLibrary.search("Spring"); for (Book book : books) { System.out.printf("Reading: %s%n", book); } return books; }
@Override public String toString() { HashMap<Book, User> bookDetails = bookLibrary.getCheckOutBookDetails(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Book\t-\tUser\n"); for (Map.Entry<Book, User> entry : bookDetails.entrySet()) { stringBuilder.append(entry.getKey() + "\t-\t" + entry.getValue().getUsername() + "\n"); } return stringBuilder.toString(); }
public void testAddPerson() { setup(); assertEquals(0, myLibrary.getPeople().size()); myLibrary.addPerson(p1); myLibrary.addPerson(p2); assertEquals(2, myLibrary.getPeople().size()); assertEquals(0, myLibrary.getPeople().indexOf(p1)); assertEquals(1, myLibrary.getPeople().indexOf(p2)); myLibrary.removePerson(p1); assertEquals(1, myLibrary.getPeople().size()); assertEquals(0, myLibrary.getPeople().indexOf(p2)); myLibrary.removePerson(p2); ; assertEquals(0, myLibrary.getPeople().size()); }
public void testAddBook() { // create test objects setup(); // Test initial size of books is 0 assertEquals(0, myLibrary.getBooks().size()); myLibrary.addBook(b1); myLibrary.addBook(b2); assertEquals(2, myLibrary.getBooks().size()); assertEquals(0, myLibrary.getBooks().indexOf(b1)); assertEquals(1, myLibrary.getBooks().indexOf(b2)); myLibrary.removeBook(b1); assertEquals(1, myLibrary.getBooks().size()); assertEquals(0, myLibrary.getBooks().indexOf(b2)); myLibrary.removeBook(b2); assertEquals(0, myLibrary.getBooks().size()); }
public void testCheckOut() { setup(); addItems(); assertTrue("Book did not check out correctly", myLibrary.checkOut(b1, p1)); assertEquals("Fred", b1.getPerson().getName()); assertFalse("Book was already checked out", myLibrary.checkOut(b1, p2)); assertTrue("Book check in failed", myLibrary.checkIn(b1)); assertFalse("Book was already checked in", myLibrary.checkIn(b1)); assertFalse("Book was never checked out", myLibrary.checkIn(b2)); setup(); p1.setMaxBooks(1); addItems(); assertTrue("First book did not check out", myLibrary.checkOut(b1, p1)); assertFalse("Second book should not have checked out", myLibrary.checkOut(b2, p1)); }
public void testGetBooksForPerson() { setup(); addItems(); assertEquals(0, myLibrary.getBooksForPerson(p1).size()); myLibrary.checkOut(b1, p1); ArrayList<Book> testBooks = myLibrary.getBooksForPerson(p1); assertEquals(1, testBooks.size()); assertEquals(0, testBooks.indexOf(b1)); myLibrary.checkOut(b2, p1); testBooks = myLibrary.getBooksForPerson(p1); assertEquals(2, testBooks.size()); assertEquals(1, testBooks.indexOf(b2)); // Additional test for maximum books setup(); p1.setMaxBooks(1); addItems(); assertTrue("First book did not check out", myLibrary.checkOut(b2, p1)); assertFalse("Second book should not have checked out", myLibrary.checkOut(b1, p1)); }
private void addItems() { myLibrary.addBook(b1); myLibrary.addBook(b2); myLibrary.addPerson(p1); myLibrary.addPerson(p2); }
public void testToString() { setup(); addItems(); assertEquals("Test: 2 books, 2 people.", myLibrary.toString()); }
@Override public void doOperation() { consoleDisplayFactory.getNewConsoleDisplay(bookLibrary.format()).display(); }