### Question:
HibernateContactDAO extends HibernatePersistentObjectDAO<Contact> implements ContactDAO { @Override public List<Contact> findByUser(Long userId, String email) { List<Object> params = new ArrayList<Object>(); if (userId != null) params.add(userId); if (email != null) params.add(email); StringBuffer sb = new StringBuffer(""); if (userId == null) sb.append(" _entity.userId is null "); else sb.append(" _entity.userId = ?1 "); if (email != null) sb.append(" and _entity.email = ?2 "); try { return findByWhere(sb.toString(), params.isEmpty() ? null : params.toArray(new Object[0]), "order by _entity.firstName, _entity.lastName", null); } catch (PersistenceException e) { log.error(e.getMessage(), e); return new ArrayList<Contact>(); } } HibernateContactDAO(); @Override List<Contact> findByUser(Long userId, String email);  }### Answer:
@Test public void testFindByUser() { List<Contact> contacts = dao.findByUser(null, null); Assert.assertEquals(1, contacts.size()); contacts = dao.findByUser(1L, null); Assert.assertEquals(2, contacts.size()); contacts = dao.findByUser(1L, "alessandro@acme.com"); Assert.assertEquals(1, contacts.size()); contacts = dao.findByUser(1L, "xxx"); Assert.assertEquals(0, contacts.size()); }