### Question:
DefaultResourceService implements ResourceService { protected long getEntityCount(EntityDefinition definition, ApiQuery apiQuery) { long count = 0; if (definition.getService() == null) { return count; } if (apiQuery == null) { return definition.getService().count(new NeutralQuery()); } int originalLimit = apiQuery.getLimit(); int originalOffset = apiQuery.getOffset(); apiQuery.setLimit(0); apiQuery.setOffset(0); if (SecurityUtil.isStaffUser()) { count = definition.getService().countBasedOnContextualRoles(apiQuery); } else { count = definition.getService().count(apiQuery); } apiQuery.setLimit(originalLimit); apiQuery.setOffset(originalOffset); return count; }  @PostConstruct void init(); @Override @MigrateResponse ServiceResponse getEntitiesByIds(final Resource resource, final String idList, final URI requestURI); @Override @MigrateResponse ServiceResponse getEntities(final Resource resource, final URI requestURI,
                                       final boolean getAllEntities); @Override @MigratePostedEntity String postEntity(final Resource resource, EntityBody entity); @Override @MigratePostedEntity void putEntity(Resource resource, String id, EntityBody entity); @Override @MigratePostedEntity void patchEntity(Resource resource, String id, EntityBody entity); @Override void deleteEntity(Resource resource, String id); @Override String getEntityType(Resource resource); @Override CalculatedData<String> getCalculatedData(Resource resource, String id); @Override CalculatedData<Map<String, Integer>> getAggregateData(Resource resource, String id); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override @MigrateResponse ServiceResponse getEntities(final Resource base, final String id, final Resource resource, final URI requestURI); @Override ServiceResponse getEntities(Resource base, String id, Resource association, Resource resource, URI requestUri);  }### Answer:
@Test public void testGetEntityCount() { String id = resourceService.postEntity(resource, new EntityBody(createTestEntity())); ApiQuery apiQuery = new ApiQuery(); apiQuery.addCriteria(new NeutralCriteria("_id", "in", Arrays.asList(id))); Long count = resourceService.getEntityCount(entityDefs.lookupByResourceName(resource.getResourceType()), apiQuery); assertEquals("Should match", 1, count.longValue()); }