### Question:
AbstractCrudService extends AbstractDaoService<E, D> { @PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, 'READ')") @Transactional(readOnly = true) public List<E> findAllWhereFieldEquals(String fieldName, Object fieldValue) { return dao.findAllWhereFieldEquals(fieldName, fieldValue); } protected  AbstractCrudService(Class<E> entityClass); @PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName())" + " or (#e.id == null and hasPermission(#e, 'CREATE'))" + " or (#e.id != null and hasPermission(#e, 'UPDATE'))") void saveOrUpdate(E e); @PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#entity, 'UPDATE')") E updatePartialWithJsonNode(E entity, JsonNode jsonObject, ObjectMapper objectMapper); @PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(returnObject, 'READ')") @Transactional(readOnly = true) E findById(Integer id); @PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(returnObject, 'READ')") @Transactional(readOnly = true) E loadById(int id); @PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, 'READ')") @Transactional(readOnly = true) List<E> findAll(); @PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, 'READ')") List<E> findAllRestricted(MultiValueMap<String, String> restrictToRequest); @PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, 'READ')") @Transactional(readOnly = true) List<E> findBySimpleFilter(MultiValueMap<String, String> requestedFilter); @PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, 'READ')") @Transactional(readOnly = true) List<E> findAllWhereFieldEquals(String fieldName, Object fieldValue); @PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, 'READ')") @Transactional(readOnly = true) List<E> findAllWithCollectionContaining(String fieldName, PersistentObject subElement); @PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#e, 'DELETE')") void delete(E e);  }### Answer:
@SuppressWarnings("unchecked") @Test public void findAllWhereFieldEquals_shouldWorkAsExpected_withValues() { final String fieldName = "id"; final Integer value = 42; doAnswer(new Answer<List<E>>() { public List<E> answer(InvocationOnMock invocation) throws InstantiationException, IllegalAccessException, NoSuchFieldException { E po = (E) implToTest.getClass().newInstance(); IdHelper.setIdOnPersistentObject(po, value); List<E> r = new ArrayList<>(); r.add(po); return r; } }).when(dao).findAllWhereFieldEquals(fieldName, value); List<E> resultList = crudService.findAllWhereFieldEquals(fieldName, value); assertNotNull(resultList); assertTrue(resultList.size() == 1); verify(dao, times(1)).findAllWhereFieldEquals(fieldName, value); }
@SuppressWarnings("unchecked") @Test public void findAllWhereFieldEquals_shouldWorkAsExpected_withNull() { final String fieldName = "id"; final Integer value = null; doAnswer(new Answer<List<E>>() { public List<E> answer(InvocationOnMock invocation) throws InstantiationException, IllegalAccessException, NoSuchFieldException { E po = (E) implToTest.getClass().newInstance(); IdHelper.setIdOnPersistentObject(po, value); List<E> r = new ArrayList<>(); r.add(po); return r; } }).when(dao).findAllWhereFieldEquals(fieldName, value); List<E> resultList = crudService.findAllWhereFieldEquals(fieldName, value); assertNotNull(resultList); assertTrue(resultList.size() == 1); verify(dao, times(1)).findAllWhereFieldEquals(fieldName, value); }