AndroidPlacesApiJsonParser implements PlacesApiJsonParser { Place readPlace(JsonReader reader) throws IOException { String description = null; String placeId = null; List<MatchedSubstring> matchedSubstrings = null; List<DescriptionTerm> terms = null; List<PlaceType> types = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "description": description = reader.nextString(); break; case "place_id": placeId = reader.nextString(); break; case "matched_substrings": matchedSubstrings = readMatchedSubstringsArray(reader); break; case "terms": terms = readDescriptionTermsArray(reader); break; case "types": types = readPlaceTypesArray(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return new Place(description, placeId, matchedSubstrings, terms, types); }  @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 readPlaceTest() throws IOException { when(parser.readPlace(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, true, true, false); when(reader.nextName()).thenReturn("description", "place_id", "matched_substrings", "terms", "types", "skip"); when(reader.nextString()).thenReturn("desc", "id"); List<MatchedSubstring> substrings = Collections.singletonList(new MatchedSubstring(1, 2)); when(parser.readMatchedSubstringsArray(reader)).thenReturn(substrings); List<DescriptionTerm> terms = Collections.singletonList(new DescriptionTerm(3, "three")); when(parser.readDescriptionTermsArray(reader)).thenReturn(terms); List<PlaceType> types = Arrays.asList(PlaceType.ROUTE, PlaceType.GEOCODE); when(parser.readPlaceTypesArray(reader)).thenReturn(types); Place expected = new Place("desc", "id", substrings, terms, types); Place actual = parser.readPlace(reader); assertEquals(expected, actual); }