@Test
public void testGetCount() throws Exception {

    assertTrue(copyShapefiles(STREAM).canRead()); // The following test
                                                    // seems to fail in the
                                                    // URL point into the
                                                    // JAR file.
    ShapefileDataStore store = new ShapefileDataStore(TestData.url(TestCaseSupport.class, STREAM));
    int count = 0;
    FeatureReader<SimpleFeatureType, SimpleFeature> reader = store.getFeatureReader();
    try {
        while (reader.hasNext()) {
            count++;
            reader.next();
        }
        assertEquals(count, store.getCount(Query.ALL));
        
        // check SimpleFeatureCollection size
        SimpleFeatureSource featureSource = store.getFeatureSource();
        SimpleFeatureCollection features = featureSource.getFeatures();
        assertEquals(count, features.size());
        assertFalse(features.isEmpty());
        
        // execute Query that returns all features
        
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        SimpleFeatureType schema = featureSource.getSchema();
        String geomName = schema.getGeometryDescriptor().getName().getLocalPart();
        
        Query query = new Query(schema.getTypeName());
        query.setPropertyNames(Query.ALL_NAMES);            
        ReferencedEnvelope bounds = features.getBounds();
        query.setFilter(ff.bbox(ff.property(geomName), bounds));
        features = featureSource.getFeatures(query);
        // check SimpleFeatureCollection size
        assertEquals(count, features.size());
        assertFalse(features.isEmpty());
     
        // execute Query that uses offset
        query = new Query(Query.ALL);
        query.setStartIndex(2);
        
        features = featureSource.getFeatures(query);
        assertEquals(count-2, features.size());
        assertEquals(count-2, featureSource.getCount(query));
        
        // execute Query that uses limit
        query = new Query(Query.ALL);
        query.setMaxFeatures(count/2);
        
        features = featureSource.getFeatures(query);
        assertEquals(count/2, features.size());
        assertEquals(count/2, featureSource.getCount(query));
        
        // execute Query that uses both limit and offset
        query = new Query(Query.ALL);
        query.setMaxFeatures(count/2);
        query.setStartIndex(2);
        
        features = featureSource.getFeatures(query);
        assertEquals(Math.min(count-2, count/2), features.size());
        assertEquals(Math.min(count-2, count/2), featureSource.getCount(query));
        
        // execute Query that doesn't return any feature
        query = new Query(Query.ALL);
        bounds = new ReferencedEnvelope(bounds.getMaxX() + 1, bounds.getMaxX() + 2, 
                bounds.getMaxY() + 1, bounds.getMaxY() + 2, bounds.getCoordinateReferenceSystem());
        query.setFilter(ff.bbox(ff.property(geomName), bounds));            
        features = featureSource.getFeatures(query);
        // check SimpleFeatureCollection size
        assertEquals(0, features.size());
        assertTrue(features.isEmpty());
    } finally {
        reader.close();
    }
    store.dispose();
}