AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<Place> readPredictionsArray(JsonReader reader) throws IOException { List<Place> predictions = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { predictions.add(readPlace(reader)); } reader.endArray(); return predictions; }  @Override PlacesAutocompleteResponse autocompleteFromStream(final InputStream is); @Override PlacesDetailsResponse detailsFromStream(final InputStream is); @Override List<Place> readHistoryJson(final InputStream in); @Override void writeHistoryJson(final OutputStream os, final List<Place> places);  }
@Test public void readPredictionsArrayTest() throws IOException { when(parser.readPredictionsArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, false); Place place = new Place("desc", "id", Collections.singletonList(new MatchedSubstring(1, 2)), Collections.singletonList(new DescriptionTerm(3, "three")), Collections.singletonList(PlaceType.GEOCODE)); when(parser.readPlace(reader)).thenReturn(place); List<Place> expected = Collections.singletonList(place); List<Place> actual = parser.readPredictionsArray(reader); assertEquals(expected, actual); }