AndroidPlacesApiJsonParser implements PlacesApiJsonParser { List<OpenPeriod> readOpenPeriodsArray(JsonReader reader) throws IOException { List<OpenPeriod> periods = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { DateTimePair open = null; DateTimePair close = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "open": open = readDateTimePair(reader); break; case "close": close = readDateTimePair(reader); break; default: reader.skipValue(); break; } } reader.endObject(); periods.add(new OpenPeriod(open, close)); } reader.endArray(); return periods; }  @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 readOpenPeriodsArrayTest() throws IOException { when(parser.readOpenPeriodsArray(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, true, false, true, false, false); when(reader.nextName()).thenReturn("open", "close", "skip"); when(parser.readDateTimePair(reader)).thenReturn(new DateTimePair("one", "two"), new DateTimePair("three", "four")); List<OpenPeriod> expected = Arrays.asList(new OpenPeriod(new DateTimePair("one", "two"), new DateTimePair("three", "four")), new OpenPeriod(null, null)); List<OpenPeriod> actual = parser.readOpenPeriodsArray(reader); assertEquals(expected, actual); }