### Question:
GenericHibernateDao { @SuppressWarnings("unchecked") public List<E> findAllWhereFieldEquals(String fieldName, Object fieldEntity, Criterion... criterion) { Class<?> fieldEntityType = null; if (fieldEntity != null) { fieldEntityType = fieldEntity.getClass(); } final boolean isField = EntityUtil.isField(entityClass, fieldName, fieldEntityType, true); if (!isField) { String errorMsg = String.format( "There is no field '%s' in the type '%s' that accepts instances of '%s'", fieldName, entityClass.getName(), fieldEntityType.getName() ); throw new IllegalArgumentException(errorMsg); } Criteria criteria = createDistinctRootEntityCriteria(criterion); if (fieldEntity == null) { criteria.add(Restrictions.isNull(fieldName)); } else { criteria.add(Restrictions.eq(fieldName, fieldEntity)); } criteria.setCacheable(this.useQueryCache); 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 findAllWhereFieldEquals_shouldThrowIfFieldIsNotAField() { boolean catchedException = false; try { this.appDao.findAllWhereFieldEquals("non_existing_field", "value"); } catch (Exception e) { String msg = e.getMessage(); assertEquals("There is no field 'non_existing_field' in the type " + "'de.terrestris.shoguncore.model.Application' that accepts instances of 'java.lang.String'", msg); catchedException = true; } assertTrue("findAllWhereFieldEquals() does throw with invalid field", catchedException); }