AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<PlacePhoto> readPhotosArray(JsonReader reader) throws IOException { List<PlacePhoto> photos = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { int height = -1; int width = -1; String photoReference = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "height": height = reader.nextInt(); break; case "width": width = reader.nextInt(); break; case "photo_reference": photoReference = reader.nextString(); break; default: reader.skipValue(); break; } } reader.endObject(); photos.add(new PlacePhoto(height, width, photoReference)); } reader.endArray(); return photos; }  @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 readPhotosArrayTest() throws IOException { when(parser.readPhotosArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, true, false, true, false, false); when((reader.nextName())).thenReturn("height", "width", "photo_reference", "skip"); when(reader.nextInt()).thenReturn(1, 2); when(reader.nextString()).thenReturn("photo"); List<PlacePhoto> expected = Arrays.asList(new PlacePhoto(1, 2, "photo"), new PlacePhoto(-1, -1, null)); List<PlacePhoto> actual = parser.readPhotosArray(reader); assertEquals(expected, actual); }