AndroidPlacesApiJsonParser implements PlacesApiJsonParser { PlaceGeometry readGeometry(JsonReader reader) throws IOException { double lat = -1.0; double lng = -1.0; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "lat": lat = reader.nextDouble(); break; case "lng": lng = reader.nextDouble(); break; default: reader.skipValue(); break; } } reader.endObject(); return new PlaceGeometry(new PlaceLocation(lat, lng)); }  @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 readGeometryTest() throws IOException { when(parser.readGeometry(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, false); when(reader.nextName()).thenReturn("lat", "lng", "skip"); when(reader.nextDouble()).thenReturn(1.0, 2.0); PlaceGeometry expected = new PlaceGeometry(new PlaceLocation(1.0, 2.0)); PlaceGeometry actual = parser.readGeometry(reader); assertEquals(expected, actual); }