AbstractEntityDao extends JpaDaoSupport implements
        EntityDao<T> { @SuppressWarnings("unchecked") protected final T findUniqueResult(String queryString, Object... values) { List<T> list = getJpaTemplate().find(queryString, values); if (list.size() > 1) { throw new IllegalStateException( "Found more matches for unique result for class " + clazz.getCanonicalName()); } return !list.isEmpty() ? list.get(0) : null; } AbstractEntityDao(Class<T> clazz); void persist(T entity); T merge(T entity); @Override T load(Integer id); @Override void delete(T entity);  }
@Test public void findUniqueResultEmpty() { String query = "select e from NamedEntityTable e"; assertNull("file not null.", dao.findUniqueResult(query)); }
@Test(expected = IllegalStateException.class) public void findUniqueResultMoreThenOne() { setupNamedEntities(); String query = "select e from NamedEntityTable e"; dao.findUniqueResult(query); }
@Test public void findUniqueResult() { setupNamedEntities(); String query = "select e from NamedEntityTable e where e.name = ?1"; assertNotNull("file not found.", dao.findUniqueResult(query, "name")); }