AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<AddressComponent> readAddressComponentsArray(JsonReader reader) throws IOException { List<AddressComponent> addressComponents = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { String longName = null; String shortName = null; List<AddressComponentType> types = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "long_name": longName = reader.nextString(); break; case "short_name": shortName = reader.nextString(); break; case "types": types = readAddressComponentTypesArray(reader); break; default: reader.skipValue(); break; } } reader.endObject(); addressComponents.add(new AddressComponent(longName, shortName, types)); } reader.endArray(); return addressComponents; }  @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 readAddressComponentsArrayTest() throws IOException { when(parser.readAddressComponentsArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, true, false, true, false, false); when(reader.nextName()).thenReturn("long_name", "short_name", "types", "skip"); when(reader.nextString()).thenReturn("long", "short"); List<AddressComponentType> types = Arrays.asList(AddressComponentType.ROOM, AddressComponentType.FLOOR); when(parser.readAddressComponentTypesArray(reader)).thenReturn(types); List<AddressComponent> expected = Arrays.asList(new AddressComponent("long", "short", types), new AddressComponent(null, null, null)); List<AddressComponent> actual = parser.readAddressComponentsArray(reader); assertEquals(expected, actual); }