WKTFileReader { public void readFeatures(@NonNull final File wkt, @NonNull final WKTFileReader.OnWKTFileReaderListener listener) { try { final LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(wkt)); while (lineNumberReader.readLine() != null) { } lineNumber = lineNumberReader.getLineNumber(); listener.onStart(lineNumber); final WKTReader.OnWKTReaderListener onWKTReaderListener = new WKTReader.OnWKTReaderListener() { @Override public void onProgress(int progress, @NonNull Feature feature) { listener.onProgress(progress, lineNumber, feature); } @Override public void onFinish(@NonNull FeatureCollection featureCollection) { listener.onFinish(featureCollection); } @Override public void onError(Throwable t) { listener.onError(t); } }; wktReader.readFeatures(new FileReader(wkt), onWKTReaderListener); } catch (IOException ioe) { listener.onError(ioe); } } WKTFileReader(); void readFeatures(@NonNull final File wkt,
                             @NonNull final WKTFileReader.OnWKTFileReaderListener listener);  }
@Test public void testReadFeatures() throws Exception { final File wkt = getFixtureAsFile("features.wkt"); new WKTFileReader().readFeatures(wkt, onWKTFileReaderListener); verify(onWKTFileReaderListener).onStart(3); verify(onWKTFileReaderListener, never()).onError(any(Throwable.class)); verify(onWKTFileReaderListener, times(3)).onProgress(anyInt(), eq(3), any(Feature.class)); verify(onWKTFileReaderListener).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 testReadFeaturesFromInvalidFile() throws Exception { final File wkt = getFixtureAsFile("featurestyle.json"); new WKTFileReader().readFeatures(wkt, onWKTFileReaderListener); verify(onWKTFileReaderListener).onStart(anyInt()); verify(onWKTFileReaderListener, never()).onProgress(anyInt(), anyInt(), any(Feature.class)); verify(onWKTFileReaderListener).onFinish(featureCollectionArgumentCaptor.capture()); final FeatureCollection featureCollection = featureCollectionArgumentCaptor.getValue(); assertNotNull(featureCollection); assertTrue(featureCollection.isEmpty()); }
@Test public void testReadFeaturesFromMissingFile() throws Exception { final File wkt = getFixtureAsFile(""); new WKTFileReader().readFeatures(wkt, onWKTFileReaderListener); verify(onWKTFileReaderListener).onError(any(Throwable.class)); verify(onWKTFileReaderListener, never()).onStart(anyInt()); verify(onWKTFileReaderListener, never()).onProgress(anyInt(), anyInt(), any(Feature.class)); verify(onWKTFileReaderListener, never()).onFinish(any(FeatureCollection.class)); }