WKTReader { public void readFeatures(@NonNull final Reader in, @NonNull final OnWKTReaderListener listener) { final FeatureCollection featureCollection = new FeatureCollection(); final BufferedReader bufferedReader = new BufferedReader(in); int currentLine = 0; String line; try { while ((line = bufferedReader.readLine()) != null) { final Matcher matcher = wktLinePattern.matcher(line); if (matcher.matches()) { try { final Feature feature = new Feature(matcher.group(1), wktReader.read(matcher.group(2))); featureCollection.addFeature(feature); listener.onProgress(currentLine + 1, feature); } catch (ParseException pe) { Log.w(TAG, pe.getMessage()); } } currentLine++; } listener.onFinish(featureCollection); bufferedReader.close(); } catch (IOException ioe) { Log.w(TAG, ioe.getMessage()); listener.onError(ioe); } } WKTReader(); void readFeatures(@NonNull final Reader in,
                             @NonNull final OnWKTReaderListener listener); @NonNull List<Feature> readFeatures(@NonNull final Reader in); @NonNull FeatureCollection readFeatureCollection(@NonNull final Reader in);  }
@Test public void testReadFeaturesThroughCallback() throws Exception { final String wkt = getFixture("features.wkt"); new WKTReader().readFeatures(new StringReader(wkt), onWKTReaderListener); verify(onWKTReaderListener, never()).onError(any(Throwable.class)); verify(onWKTReaderListener, times(3)).onProgress(anyInt(), any(Feature.class)); verify(onWKTReaderListener).onFinish(featureCollectionArgumentCaptor.capture()); final FeatureCollection featureCollection = featureCollectionArgumentCaptor.getValue(); assertNotNull(featureCollection); assertEquals(3, featureCollection.getFeatures() .size()); assertNotNull(featureCollection.getFeature("69")); assertNotNull(featureCollection.getFeature("19")); assertNotNull(featureCollection.getFeature("146")); }
@Test public void testReadFeatures() throws Exception { final String wkt = getFixture("features.wkt"); final List<Feature> features = new WKTReader().readFeatures(new StringReader(wkt)); assertNotNull(features); assertEquals(3, features.size()); assertEquals("69", features.get(0) .getId()); assertNotNull(features.get(0) .getGeometry()); assertEquals("Polygon", features.get(0) .getGeometry() .getGeometryType()); assertEquals("19", features.get(1) .getId()); assertNotNull(features.get(1) .getGeometry()); assertEquals("Polygon", features.get(1) .getGeometry() .getGeometryType()); assertEquals("146", features.get(2) .getId()); assertNotNull(features.get(2) .getGeometry()); assertEquals("Polygon", features.get(2) .getGeometry() .getGeometryType()); }