### Question:
AbstractCrudService extends AbstractDaoService<E, D> { @PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(returnObject, 'READ')") @Transactional(readOnly = true) public E findById(Integer id) { return dao.findById(id); } 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:
@Test public void findById_shouldFindExistingId() throws NoSuchFieldException, IllegalAccessException { Integer existingId = 17; IdHelper.setIdOnPersistentObject(implToTest, existingId); doReturn(implToTest).when(dao).findById(existingId); E result = crudService.findById(existingId); assertNotNull(result); assertEquals(existingId, result.getId()); verify(dao, times(1)).findById(existingId); }
@Test public void saveOrUpdate_shouldReturnNullForNonExistingId() { Integer nonExistingId = 42; doReturn(null).when(dao).findById(nonExistingId); E result = crudService.findById(nonExistingId); assertNull(result); verify(dao, times(1)).findById(nonExistingId); }