MockGtfs { public void putCalendarDates(String... specs) { List<String> serviceIds = new ArrayList<String>(); List<String> serviceDates = new ArrayList<String>(); List<String> exceptionTypes = new ArrayList<String>(); for (String spec : specs) { int index = spec.indexOf('='); if (index == -1) { throw new IllegalArgumentException("invalid calendar date spec=" + spec); } String serviceId = spec.substring(0, index); String dates = spec.substring(index + 1); for (String date : dates.split(",")) { int exceptionType = 1; if (date.startsWith("-")) { exceptionType = 2; date = date.substring(1); } serviceIds.add(serviceId); serviceDates.add(date); exceptionTypes.add(Integer.toString(exceptionType)); } } TableBuilder b = new TableBuilder(serviceIds.size()); b.addColumnSpec("service_id", serviceIds); b.addColumnSpec("date", serviceDates); b.addColumnSpec("exception_type", exceptionTypes); putFile("calendar_dates.txt", b.build()); } MockGtfs(File path); static MockGtfs create(); File getPath(); void putFile(String fileName, String content); void putFile(String fileName, File file); void putLines(String fileName, String... rows); GtfsMutableRelationalDao read(); GtfsMutableRelationalDao read(GtfsReader reader); void putMinimal(); void putAgencies(int numberOfRows, String... columns); void putDefaultAgencies(); void putRoutes(int numberOfRows, String... columns); void putDefaultRoutes(); void putStops(int numberOfRows, String... columns); void putDefaultStops(); void putCalendars(int numberOfServiceIds, String... columns); void putDefaultCalendar(); void putCalendarDates(String... specs); void putTrips(int numberOfRows, String routeIds, String serviceIds,
      String... columns); void putDefaultTrips(); void putStopTimes(String tripIds, String stopIds); void putDefaultStopTimes(); AgencyAndId id(String id);  }
@Test public void testPutCalendarDates() throws IOException { _gtfs.putMinimal(); _gtfs.putCalendarDates("sid0=20120901,-20120902", "sid1=20120903"); GtfsRelationalDao dao = _gtfs.read(); List<ServiceCalendarDate> dates = dao.getCalendarDatesForServiceId(new AgencyAndId( "a0", "sid0")); assertEquals(2, dates.size()); assertEquals(new ServiceDate(2012, 9, 1), dates.get(0).getDate()); assertEquals(1, dates.get(0).getExceptionType()); assertEquals(new ServiceDate(2012, 9, 2), dates.get(1).getDate()); assertEquals(2, dates.get(1).getExceptionType()); dates = dao.getCalendarDatesForServiceId(new AgencyAndId("a0", "sid1")); assertEquals(1, dates.size()); assertEquals(new ServiceDate(2012, 9, 3), dates.get(0).getDate()); assertEquals(1, dates.get(0).getExceptionType()); }