borrowList.add(book2);
book1.setAvailability(Available.BORROWED);
book2.setAvailability(Available.BORROWED);
// Borrow with ID 1
Borrow borrow = new Borrow(entityManager.find(Reader.class, 1l), borrowList,
new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()));
entityManager.close();
entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(borrow);
// because of lazy loading of collections in hibernate
borrow.getTitles().get(0).getId();
entityManager.getTransaction().commit();
entityManager.close();
List<Book> returnList = new ArrayList<Book>();
returnList.add(book1);
em.getTransaction().begin();
borrowDAO.returnBooks(borrow, returnList);
em.getTransaction().commit();
entityManager = entityManagerFactory.createEntityManager();
Borrow testBorrow = entityManager.find(Borrow.class, 1l);
assertFalse("Borrow list should not contain book with id 1", testBorrow.getTitles().contains(book1));
entityManager.close();
}