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