AndroidPlacesApiJsonParser implements PlacesApiJsonParser { @SuppressWarnings("ConstantConditions") PlaceDetails readPlaceDetails(JsonReader reader) throws IOException { List<AddressComponent> addressComponents = null; String formattedAddress = null; String formattedPhoneNumber = null; String internationalPhoneNumber = null; PlaceGeometry geometry = null; String icon = null; String name = null; String placeId = null; OpenHours openingHours = null; boolean permanentlyClosed = false; List<PlacePhoto> photos = null; PlaceScope scope = null; List<AlternativePlaceId> altIds = null; int priceLevel = -1; double rating = -1.0; List<PlaceReview> reviews = null; List<String> types = null; String url = null; String vicinity = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "address_components": addressComponents = readAddressComponentsArray(reader); break; case "formatted_address": formattedAddress = reader.nextString(); break; case "formatted_phone_number": formattedPhoneNumber = reader.nextString(); break; case "international_phone_number": internationalPhoneNumber = reader.nextString(); break; case "geometry": geometry = readGeometry(reader); break; case "icon": icon = reader.nextString(); break; case "name": name = reader.nextString(); break; case "place_id": placeId = reader.nextString(); break; case "opening_hours": openingHours = readOpeningHours(reader); break; case "permanently_closed": permanentlyClosed = reader.nextBoolean(); break; case "photos": photos = readPhotosArray(reader); break; case "scope": scope = readScope(reader); break; case "alt_ids": altIds = readAltIdsArray(reader); break; case "price_level": priceLevel = reader.nextInt(); break; case "rating": rating = reader.nextDouble(); break; case "reviews": reviews = readReviewsArray(reader); break; case "types": types = readTypesArray(reader); break; case "url": url = reader.nextString(); break; case "vicinity": vicinity = reader.nextString(); break; default: reader.skipValue(); break; } } reader.endObject(); return new PlaceDetails(addressComponents, formattedAddress, formattedPhoneNumber, internationalPhoneNumber, geometry, icon, name, placeId, openingHours, permanentlyClosed, photos, scope, altIds, priceLevel, rating, reviews, types, url, vicinity); }  @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 readPlaceDetailsTest() throws IOException { when(parser.readPlaceDetails(reader)).thenCallRealMethod(); Boolean[] hasNextValues = new Boolean[20]; Arrays.fill(hasNextValues, 0, 19, Boolean.TRUE); hasNextValues[19] = Boolean.FALSE; when(reader.hasNext()).thenReturn(true, hasNextValues); String[] names = new String[] { "address_components", "formatted_address", "formatted_phone_number", "international_phone_number", "geometry", "icon", "name", "place_id", "opening_hours", "permanently_closed", "photos", "scope", "alt_ids", "price_level", "rating", "reviews", "types", "url", "vicinity" }; when(reader.nextName()).thenReturn("skip", names); when(parser.readAddressComponentsArray(reader)).thenReturn(Collections.singletonList(new AddressComponent("long", "short", Collections.singletonList(AddressComponentType.ROOM)))); when(reader.nextString()).thenReturn("addr", "phone", "intl_phone", "icon", "name", "id", "url", "vic"); when(parser.readGeometry(reader)).thenReturn(new PlaceGeometry(new PlaceLocation(1.0, 2.0))); when(parser.readOpeningHours(reader)).thenReturn(new OpenHours(true, Collections.singletonList(new OpenPeriod(new DateTimePair("one", "two"), new DateTimePair("three", "four"))))); when(reader.nextBoolean()).thenReturn(true); when(parser.readPhotosArray(reader)).thenReturn(Collections.singletonList(new PlacePhoto(1, 2, "ref"))); when(parser.readScope(reader)).thenReturn(PlaceScope.GOOGLE); when(parser.readAltIdsArray(reader)).thenReturn(Collections.singletonList(new AlternativePlaceId("id", PlaceScope.GOOGLE))); when(reader.nextInt()).thenReturn(5); when(reader.nextDouble()).thenReturn(5.0); when(parser.readReviewsArray(reader)).thenReturn(Collections.singletonList(new PlaceReview(Collections.singletonList(new RatingAspect(5, "quality")), "name", "url", "en", 4, "txt", 10L))); when(parser.readTypesArray(reader)).thenReturn(Collections.singletonList("type")); PlaceDetails expected = new PlaceDetails(Collections.singletonList(new AddressComponent("long", "short", Collections.singletonList(AddressComponentType.ROOM))), "addr", "phone", "intl_phone", new PlaceGeometry(new PlaceLocation(1.0, 2.0)), "icon", "name", "id", new OpenHours(true, Collections.singletonList(new OpenPeriod(new DateTimePair("one", "two"), new DateTimePair("three", "four")))), true, Collections.singletonList(new PlacePhoto(1, 2, "ref")), PlaceScope.GOOGLE, Collections.singletonList(new AlternativePlaceId("id", PlaceScope.GOOGLE)), 5, 5.0, Collections.singletonList(new PlaceReview(Collections.singletonList(new RatingAspect(5, "quality")), "name", "url", "en", 4, "txt", 10L)), Collections.singletonList("type"), "url", "vic"); PlaceDetails actual = parser.readPlaceDetails(reader); assertEquals(expected, actual); }