### Question:
HibernateUserHistoryDAO extends HibernatePersistentObjectDAO<UserHistory> implements UserHistoryDAO { public List<UserHistory> findByUserId(long userId) { try { return findByWhere("_entity.userId =" + userId, "order by _entity.date asc", null); } catch (PersistenceException e) { log.error(e.getMessage(), e); return new ArrayList<UserHistory>(); } } private  HibernateUserHistoryDAO(); List<UserHistory> findByUserId(long userId); @Override void createUserHistory(User user, String eventType, String comment, String ip, String sessionId); @Override void cleanOldHistories(int ttl); @Override boolean store(UserHistory history);  }### Answer:
@Test public void testDelete() throws PersistenceException { Collection<UserHistory> histories = (Collection<UserHistory>) dao.findByUserId(1); Assert.assertNotNull(histories); Assert.assertEquals(2, histories.size()); for (UserHistory history : histories) { boolean result = dao.delete(history.getId()); Assert.assertTrue(result); } histories = (Collection<UserHistory>) dao.findByUserId(4); Assert.assertNotNull(histories); Assert.assertEquals(0, histories.size()); }
@SuppressWarnings("rawtypes") @Test public void testFindByUserId() { Collection histories = dao.findByUserId(1); Assert.assertNotNull(histories); Assert.assertEquals(2, histories.size()); histories = dao.findByUserId(99); Assert.assertNotNull(histories); Assert.assertEquals(0, histories.size()); }