AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<RatingAspect> readAspectsArray(JsonReader reader) throws IOException { List<RatingAspect> aspects = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { int rating = -1; String type = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "rating": rating = reader.nextInt(); break; case "type": type = reader.nextString(); break; default: reader.skipValue(); break; } } reader.endObject(); aspects.add(new RatingAspect(rating, type)); } reader.endArray(); return aspects; }  @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 readAspectsArrayTest() throws IOException { when(parser.readAspectsArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, false, true, false, false); when(reader.nextName()).thenReturn("rating", "type", "skip"); when(reader.nextInt()).thenReturn(1); when(reader.nextString()).thenReturn("one"); List<RatingAspect> expected = Arrays.asList(new RatingAspect(1, "one"), new RatingAspect(-1, null)); List<RatingAspect> actual = parser.readAspectsArray(reader); assertEquals(expected, actual); }