public void testFindAvailableCopyReturnsNullWhenCopyIsBorrowed() throws Exception { gateway.addCopy(new Book("isbn2", "Peace and War", "Toy Story")).getId(); List copies = gateway.findAllCopies("isbn2"); MediaCopy copy = (MediaCopy) copies.get(0); copy.setLoaned(new LoanReceipt(new Patron(DateUtil.dateFromString("1/1/2000")))); assertEquals(null, gateway.findAvailableCopy("isbn2")); }
public MediaCopy findAvailableCopy(String id) { List copies = findAllCopies(id); for (int i = 0; i < copies.size(); i++) { MediaCopy copy = (MediaCopy) copies.get(i); if (!copy.isLoaned()) return copy; } return null; }
public void testFindAvailableCopyReturnsCopyWhenOneCopyOfManyIsBorrowed() throws Exception { gateway.addCopies(new Book("isbn1", "Peace and War 1", "Toy Story"), 2); List copies = gateway.findAllCopies("isbn1"); MediaCopy copy = (MediaCopy) copies.get(0); copy.setLoaned(new LoanReceipt(new Patron(DateUtil.dateFromString("1/1/2000")))); assertNotNull(gateway.findAvailableCopy("isbn1")); }
protected void setUp() throws Exception { super.setUp(); gateway = new MockMediaGateway(); copy1 = gateway.addCopy(new Book("isbn", "War and Peace", "Tolstoy")); id1 = copy1.getId(); copy2 = gateway.addCopy(new Book("isbn", "War and Peace", "Tolstoy")); id2 = copy2.getId(); }
public void testOldEnough() throws Exception { Date davidIsElevenToday = DateUtil.dateFromString("1/1/2011"); TimeSource.timeSource = new MockTimeSource(davidIsElevenToday); MediaCopy copy = library.acceptBook("0316769533"); // Catcher in the Rye copy.getMedia().setAgeRestriction(10); LoanReceipt receipt = library.loan(copy, patron); assertEquals(LoanReceipt.OK, receipt.getStatus()); }
public MediaCopy findCdCopy(String barCode) { List copies = (List) this.mediaCopies.get(barCode); if (copies != null) { for (Iterator i = copies.iterator(); i.hasNext(); ) { MediaCopy copy = (MediaCopy) i.next(); if (copy.isCdCopy()) return copy; } return null; } else return null; }
public MediaCopy findBookCopy(String isbn) { List copies = (List) this.mediaCopies.get(isbn); if (copies != null) { for (Iterator i = copies.iterator(); i.hasNext(); ) { MediaCopy copy = (MediaCopy) i.next(); if (copy.isBookCopy()) return copy; } return null; } else return null; }
public MediaCopy findCopyById(String copyId) { Collection listsOfCopies = mediaCopies.values(); for (Iterator i = listsOfCopies.iterator(); i.hasNext(); ) { List copies = (List) i.next(); for (int j = 0; j < copies.size(); j++) { MediaCopy mediaCopy = (MediaCopy) copies.get(j); if (mediaCopy.getId().equals(copyId)) return mediaCopy; } } return null; }
public List findAllLoanReceiptsFor(String patronId) { List receipts = new LinkedList(); Collection copyLists = mediaCopies.values(); for (Iterator i = copyLists.iterator(); i.hasNext(); ) { List copyList = (List) i.next(); for (int j = 0; j < copyList.size(); j++) { MediaCopy mediaCopy = (MediaCopy) copyList.get(j); LoanReceipt receipt = mediaCopy.getLoanReceipt(); if (receipt != null && receipt.getBorrower().getId().equals(patronId)) receipts.add(receipt); } } return receipts; }
public void testDeleteThreeCopiesForValidIsbn() throws Exception { assertISBNKnownWithEntries("3", 3); assertEquals(6, mockInMemoryMediaGateway.copyCount()); List copies = mockInMemoryMediaGateway.findAllCopies("3"); for (Iterator iter = copies.iterator(); iter.hasNext(); ) { MediaCopy copy = (MediaCopy) iter.next(); String id = copy.getId(); request.setParameter("delete_" + id, "on"); } ActionResult result = booksController.handle(request); assertTrue(mockInMemoryMediaGateway.contains("3")); assertISBNKnownWithEntries("3", 0); assertEquals(3, mockInMemoryMediaGateway.copyCount()); assertTrue(result.getInfoMessage().length() > 0); assertEquals("", result.getWarningMessage()); assertEquals("", result.getErrorMessage()); }
public void testShouldSetCopyToBorrowed() throws Exception { receipt = library.loan(copy, patron); assertTrue(copy.isLoaned()); }