AndroidPlacesApiJsonParser implements PlacesApiJsonParser { OpenHours readOpeningHours(JsonReader reader) throws IOException { boolean openNow = false; List<OpenPeriod> periods = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "open_now": openNow = reader.nextBoolean(); break; case "periods": periods = readOpenPeriodsArray(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return new OpenHours(openNow, 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 readOpeningHoursTest() throws IOException { when(parser.readOpeningHours(reader)).thenCallRealMethod(); when(reader.hasNext()).thenReturn(true, true, true, false); when(reader.nextName()).thenReturn("open_now", "periods", "skip"); when(reader.nextBoolean()).thenReturn(true); List<OpenPeriod> periods = Collections.singletonList(new OpenPeriod(new DateTimePair("one", "two"), new DateTimePair("three", "four"))); when(parser.readOpenPeriodsArray(reader)).thenReturn(periods); OpenHours expected = new OpenHours(true, periods); OpenHours actual = parser.readOpeningHours(reader); assertEquals(expected, actual); }