AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<AlternativePlaceId> readAltIdsArray(JsonReader reader) throws IOException { List<AlternativePlaceId> altIds = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { String placeId = null; PlaceScope scope = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "place_id": placeId = reader.nextString(); break; case "scope": scope = readScope(reader); break; default: reader.skipValue(); break; } } reader.endObject(); altIds.add(new AlternativePlaceId(placeId, scope)); } reader.endArray(); return altIds; }  @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 readAltIdsArrayTest() throws IOException { when(parser.readAltIdsArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, false, true, false, false); when(reader.nextName()).thenReturn("place_id", "scope", "skip"); when(reader.nextString()).thenReturn("id"); when(parser.readScope(reader)).thenReturn(PlaceScope.GOOGLE); List<AlternativePlaceId> expected = Arrays.asList(new AlternativePlaceId("id", PlaceScope.GOOGLE), new AlternativePlaceId(null, null)); List<AlternativePlaceId> actual = parser.readAltIdsArray(reader); assertEquals(expected, actual); }