AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<PlaceReview> readReviewsArray(JsonReader reader) throws IOException { List<PlaceReview> reviews = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { List<RatingAspect> aspects = null; String authorName = null; String authorUrl = null; String language = null; int rating = -1; String text = null; long time = -1L; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "aspects": aspects = readAspectsArray(reader); break; case "author_name": authorName = reader.nextString(); break; case "author_url": authorUrl = reader.nextString(); break; case "language": language = reader.nextString(); break; case "rating": rating = reader.nextInt(); break; case "text": text = reader.nextString(); break; case "time": time = reader.nextLong(); break; default: reader.skipValue(); break; } } reader.endObject(); reviews.add(new PlaceReview(aspects, authorName, authorUrl, language, rating, text, time)); } reader.endArray(); return reviews; }  @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 readReviewsArrayTest() throws IOException { when(parser.readReviewsArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, true, true, true, true, true, true, false, true, false, false); when(reader.nextName()).thenReturn("aspects", "author_name", "author_url", "language", "rating", "text", "time", "skip"); List<RatingAspect> aspects = Arrays.asList(new RatingAspect(1, "one"), new RatingAspect(-1, null)); when(parser.readAspectsArray(reader)).thenReturn(aspects); when(reader.nextString()).thenReturn("name", "url", "lang", "txt"); when(reader.nextInt()).thenReturn(1); when(reader.nextLong()).thenReturn(10L); List<PlaceReview> expected = Arrays.asList(new PlaceReview(aspects, "name", "url", "lang", 1, "txt", 10L), new PlaceReview(null, null, null, null, -1, null, -1L)); List<PlaceReview> actual = parser.readReviewsArray(reader); assertEquals(expected, actual); }