Esempio n. 1
0
 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"));
 }
Esempio n. 2
0
 public void testGetAllISBNsDoesNotIncludeCompactDiscs() {
   gateway.addCopies(
       new CompactDisc("abcd", "Peace and War, The Musical", "Gilbertolov and Sullivanalov"), 2);
   gateway.addCopies(new CompactDisc("xyz", "The White Album", "The Beatles"), 2);
   Map isbnsTitles = gateway.findAllISBNsAndTitles();
   assertEquals(1, isbnsTitles.size());
   assertEquals(6, gateway.copyCount());
 }
Esempio n. 3
0
  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"));
  }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 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());
 }
Esempio n. 6
0
 public void testGetAllISBNs() {
   gateway.addCopy(new Book("isbn2", "Peace and War", "Toy Story")).getId();
   List isbns = gateway.findAllISBNs();
   assertEquals(2, isbns.size());
   Iterator iter = isbns.iterator();
   while (iter.hasNext()) {
     String isbn = (String) iter.next();
     assertTrue(isbn, isbn.startsWith("isbn"));
   }
 }
Esempio n. 7
0
 public void testGetAllISBNsAndTitles() {
   gateway.addCopy(new Book("isbn2", "Peace and War", "Toy Story")).getId();
   gateway.addCopy(new Book("isbn3", "Son of Peace and War", "Toy Story II")).getId();
   Map isbnsTitles = gateway.findAllISBNsAndTitles();
   assertEquals(3, isbnsTitles.size());
   Iterator iter = isbnsTitles.entrySet().iterator();
   while (iter.hasNext()) {
     Entry entry = (Entry) iter.next();
     assertTrue(((String) entry.getKey()).startsWith("isbn"));
     assertTrue(((String) entry.getValue()).contains("Peace"));
   }
 }
Esempio n. 8
0
 public void testGetCopyCount() {
   gateway.addCopies(new Book("isbn1", "Peace and War 1", "Toy Story"), 2);
   gateway.addCopies(new Book("isbn2", "Peace and War 2", "Toy Story"), 3);
   gateway.addCopies(new Book("isbn3", "Peace and War 3", "Toy Story"), 1);
   assertEquals(8, gateway.copyCount());
 }
Esempio n. 9
0
 public void testCanFindMoreThanOneBook() throws Exception {
   List copies = gateway.findAllCopies("isbn");
   assertEquals(2, copies.size());
   assertTrue(copies.contains(copy1));
   assertTrue(copies.contains(copy2));
 }
Esempio n. 10
0
 public void testMediaCountShouldBeZeroWhenEmpty() {
   gateway.clear();
   assertEquals("expected empty mediaCatalog", 0, gateway.mediaCount());
 }
Esempio n. 11
0
 public void testContainsShouldReturnTrueForCorrectId() throws Exception {
   assertTrue("expected true for recognized isbn", gateway.contains("isbn"));
 }
Esempio n. 12
0
 public void testContainsShouldReturnFalseIfNoSuchBook() throws Exception {
   assertFalse(gateway.contains("noSuchBook"));
 }
Esempio n. 13
0
 public void testFindAvailableCopyShouldReturnNullIfNoSuchBook() throws Exception {
   assertNull(gateway.findAvailableCopy("noSuchBook"));
 }
Esempio n. 14
0
 public void testFindAvailableCopyReturnsCopyWhenCopyIsNotBorrowed() throws Exception {
   assertNotNull(gateway.findAvailableCopy("isbn"));
 }