### Question:
GenericHibernateDao { @SuppressWarnings("unchecked") public List<E> findAllWithCollectionContaining(String fieldName, PersistentObject subElement, Criterion... criterion) { final Class<? extends PersistentObject> subElementType = subElement.getClass(); final boolean isCollectionField = EntityUtil.isCollectionField(entityClass, fieldName, subElementType, true); if (!isCollectionField) { String errorMsg = String.format( "There is no collection field '%s' with element type '%s' in the type '%s'", fieldName, subElementType.getName(), entityClass.getName() ); throw new IllegalArgumentException(errorMsg); } Criteria criteria = createDistinctRootEntityCriteria(criterion); criteria.createAlias(fieldName, "sub"); criteria.add(Restrictions.eq("sub.id", subElement.getId())); return (List<E>) criteria.list(); } @SuppressWarnings("unchecked")  GenericHibernateDao(); protected  GenericHibernateDao(Class<E> clazz); E findById(ID id); @SuppressWarnings("unchecked") List<E> findAllWhereFieldEquals(String fieldName, Object fieldEntity,
                                           Criterion... criterion); @SuppressWarnings("unchecked") List<E> findAllWithCollectionContaining(String fieldName, PersistentObject subElement,
                                                   Criterion... criterion); E loadById(ID id); List<E> findAll(); void saveOrUpdate(E e); void delete(E e); @SuppressWarnings("unchecked") E unproxy(E e); void evict(E e); @SuppressWarnings("unchecked") List<E> findByCriteria(Criterion... criterion); @SuppressWarnings("unchecked") List<E> findByCriteriaRestricted(List<String> restrictFieldNames, Criterion... criterion); @SuppressWarnings("unchecked") E findByUniqueCriteria(Criterion... criterion); @SuppressWarnings("unchecked") PagingResult<E> findByCriteriaWithSortingAndPaging(Integer firstResult,
                                                              Integer maxResults, List<Order> sorters, Criterion... criterion); @SuppressWarnings({"unchecked"}) Map<PersistentObject, PermissionCollection> findAllUserPermissionsOfUser(User user); @SuppressWarnings({"unchecked"}) Map<PersistentObject, PermissionCollection> findAllUserGroupPermissionsOfUserGroup(UserGroup userGroup); Number getTotalCount(Criterion... criterion); Class<E> getEntityClass();  }### Answer:
@Test public void findAllWithCollectionContaining_shouldThrowIfFieldIsNotCollectionField() { boolean catchedException = false; try { this.appDao.findAllWithCollectionContaining("no_collection_field", new Plugin()); } catch (Exception e) { String msg = e.getMessage(); assertEquals("There is no collection field 'no_collection_field' with element type " + "'de.terrestris.shoguncore.model.Plugin' in the type 'de.terrestris.shoguncore.model.Application'", msg); catchedException = true; } assertTrue("findAllWithCollectionContaining() does throw with invalid collection field", catchedException); }