CollectionDao extends HibernateDao<Collection, String> { public void removeProduct (final String cid, final Long pid, User user) { Collection collection = read(cid); if (collection == null) { LOGGER.warn("Unknown collection #" + cid); return; } Product product = productDao.read(pid); if (product == null) { LOGGER.warn("Unknown product #" + pid); return; } Hibernate.initialize (collection.getProducts()); collection.getProducts().remove(product); update(collection); fireProductRemoved (new DaoEvent<> (collection), product); }  @Override void delete(final Collection collection); @Override void deleteAll(); boolean contains(final String cid, final Long pid); void removeProduct(final String cid, final Long pid, User user); void removeProducts(final String cid, final Long[] pids, User user); @SuppressWarnings ("unchecked") List<Collection> getCollectionsOfProduct(final Long product_id); List<Long> getProductIds(final String collection_uuid, User user); @SuppressWarnings("unchecked") List<String> getCollectionsUUID(); String getCollectionUUIDByName(final String collection_name); Collection getByName(final String name); Iterator<Collection> getAllCollections(); final static String HIDDEN_PREFIX; final static String COLLECTION_ROOT_NAME; }
@Test (dependsOnMethods = {"contains"}) public void removeProduct () { String cid; long pid = 5; User user = udao.read ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2"); Collection collection; cid = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1"; collection = dao.read (cid); Assert.assertTrue (dao.contains (cid, pid)); dao.removeProduct (cid, pid, user); Assert.assertFalse (dao.contains (cid, pid)); }