AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<AddressComponentType> readAddressComponentTypesArray(JsonReader reader) throws IOException { List<AddressComponentType> types = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { switch (reader.nextString()) { case "administrative_area_level_1": types.add(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_1); break; case "administrative_area_level_2": types.add(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_2); break; case "administrative_area_level_3": types.add(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_3); break; case "administrative_area_level_4": types.add(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_4); break; case "administrative_area_level_5": types.add(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_5); break; case "colloquial_area": types.add(AddressComponentType.COLLOQUIAL_AREA); break; case "country": types.add(AddressComponentType.COUNTRY); break; case "floor": types.add(AddressComponentType.FLOOR); break; case "geocode": types.add(AddressComponentType.GEOCODE); break; case "intersection": types.add(AddressComponentType.INTERSECTION); break; case "locality": types.add(AddressComponentType.LOCALITY); break; case "natural_feature": types.add(AddressComponentType.NATURAL_FEATURE); break; case "neighborhood": types.add(AddressComponentType.NEIGHBORHOOD); break; case "political": types.add(AddressComponentType.POLITICAL); break; case "point_of_interest": types.add(AddressComponentType.POINT_OF_INTEREST); break; case "post_box": types.add(AddressComponentType.POST_BOX); break; case "postal_code": types.add(AddressComponentType.POSTAL_CODE); break; case "postal_code_prefix": types.add(AddressComponentType.POSTAL_CODE_PREFIX); break; case "postal_code_suffix": types.add(AddressComponentType.POSTAL_CODE_SUFFIX); break; case "postal_town": types.add(AddressComponentType.POSTAL_TOWN); break; case "premise": types.add(AddressComponentType.PREMISE); break; case "room": types.add(AddressComponentType.ROOM); break; case "route": types.add(AddressComponentType.ROUTE); break; case "street_address": types.add(AddressComponentType.STREET_ADDRESS); break; case "street_number": types.add(AddressComponentType.STREET_NUMBER); break; case "sublocality": types.add(AddressComponentType.SUBLOCALITY); break; case "sublocality_level_1": types.add(AddressComponentType.SUBLOCALITY_LEVEL_1); break; case "sublocality_level_2": types.add(AddressComponentType.SUBLOCALITY_LEVEL_2); break; case "sublocality_level_3": types.add(AddressComponentType.SUBLOCALITY_LEVEL_3); break; case "sublocality_level_4": types.add(AddressComponentType.SUBLOCALITY_LEVEL_4); break; case "sublocality_level_5": types.add(AddressComponentType.SUBLOCALITY_LEVEL_5); break; case "subpremise": types.add(AddressComponentType.SUBPREMISE); break; case "transit_station": types.add(AddressComponentType.TRANSIT_STATION); break; default: reader.skipValue(); break; } } reader.endArray(); return types; }  @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 readAddressComponentTypesArrayTest() throws IOException { when(parser.readAddressComponentTypesArray(reader)).thenCallRealMethod(); int numOfTypes = AddressComponentType.values().length; Boolean[] hasNextValues = new Boolean[numOfTypes + 1]; Arrays.fill(hasNextValues, 0, numOfTypes, Boolean.TRUE); hasNextValues[numOfTypes] = Boolean.FALSE; when(reader.hasNext()).thenReturn(true, hasNextValues); String[] types = new String[] { "administrative_area_level_1", "administrative_area_level_2", "administrative_area_level_3", "administrative_area_level_4", "administrative_area_level_5", "colloquial_area", "country", "floor", "geocode", "intersection", "locality", "natural_feature", "neighborhood", "political", "point_of_interest", "post_box", "postal_code", "postal_code_prefix", "postal_code_suffix", "postal_town", "premise", "room", "route", "street_address", "street_number", "sublocality", "sublocality_level_1", "sublocality_level_2", "sublocality_level_3", "sublocality_level_4", "sublocality_level_5", "subpremise", "transit_station" }; when(reader.nextString()).thenReturn("skip", types); List<AddressComponentType> expected = new ArrayList<>(); for (String type : types) { expected.add(AddressComponentType.valueOf(type.toUpperCase())); } List<AddressComponentType> actual = parser.readAddressComponentTypesArray(reader); assertEquals(expected, actual); }