public void testAddCopiesCreatesUniqueIds() throws Exception {
   List copies = gateway.addCopies(new Book("isbn", "War and Peace", "Tolstoy"), 3);
   assertEquals(3, copies.size());
   assertEquals(5, gateway.findAllCopies("isbn").size());
   Set ids = new HashSet();
   for (Iterator iter = gateway.findAllCopies("isbn").iterator(); iter.hasNext(); )
     ids.add(((MediaCopy) iter.next()).getId());
   assertEquals(5, ids.size());
 }
 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 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"));
  }
 public void testCanFindMoreThanOneBook() throws Exception {
   List copies = gateway.findAllCopies("isbn");
   assertEquals(2, copies.size());
   assertTrue(copies.contains(copy1));
   assertTrue(copies.contains(copy2));
 }