GtfsRealtimeTripLibrary { public VehicleLocationRecord createVehicleLocationRecordForUpdate( CombinedTripUpdatesAndVehiclePosition update) { return createVehicleLocationRecordForUpdate(null, update); }  void setValidateCurrentTime(boolean validate); void setEntitySource(GtfsRealtimeEntitySource entitySource); void setBlockCalendarService(BlockCalendarService blockCalendarService); long getCurrentTime(); void setCurrentTime(long currentTime); void setCurrentTime(long currentTime, int originOffsetHours); void setStopModificationStrategy(StopModificationStrategy strategy); void setScheduleAdherenceFromLocation(boolean scheduleAdherenceFromLocation); void setBlockGeospatialService(BlockGeospatialService blockGeospatialService); void setUseLabelAsVehicleId(boolean useLabelAsVehicleId); List<CombinedTripUpdatesAndVehiclePosition> groupTripUpdatesAndVehiclePositions(
      FeedMessage tripUpdateMessage, FeedMessage vehiclePositionsMessage); List<CombinedTripUpdatesAndVehiclePosition> groupTripUpdatesAndVehiclePositions(MonitoredResult result,
      FeedMessage tripUpdateMessage, FeedMessage vehiclePositionsMessage); VehicleLocationRecord createVehicleLocationRecordForUpdate(
      CombinedTripUpdatesAndVehiclePosition update); VehicleLocationRecord createVehicleLocationRecordForUpdate(MonitoredResult result,
        CombinedTripUpdatesAndVehiclePosition update);  }
@Test public void testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates() { TripUpdate tripUpdate = TripUpdate.newBuilder() .setTrip(TripDescriptor.newBuilder().setTripId("tripA")) .setDelay(120) .setTimestamp(123456789) .build(); TripEntryImpl tripA = trip("tripA"); stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0); BlockEntryImpl blockA = block("blockA"); BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA); BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L); Mockito.when( _blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn( Arrays.asList(blockInstanceA)); CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition(); update.block = new BlockDescriptor(); update.block.setBlockInstance(blockInstanceA); update.tripUpdates = Arrays.asList(tripUpdate); VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update); assertEquals(123456789000L, record.getTimeOfRecord()); assertEquals(120, record.getScheduleDeviation(), 0.0); }
@Test public void testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates() { StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder(); stopTimeUpdate.setStopId("stopA"); StopTimeEvent.Builder stopTimeEvent = StopTimeEvent.newBuilder(); stopTimeEvent.setDelay(180); stopTimeUpdate.setDeparture(stopTimeEvent); TripUpdate tripUpdate = TripUpdate.newBuilder() .setTrip(TripDescriptor.newBuilder().setTripId("tripA")) .setDelay(120) .setTimestamp(123456789) .addStopTimeUpdate(stopTimeUpdate) .build(); TripEntryImpl tripA = trip("tripA"); stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0); BlockEntryImpl blockA = block("blockA"); BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA); BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L); Mockito.when( _blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn( Arrays.asList(blockInstanceA)); CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition(); update.block = new BlockDescriptor(); update.block.setBlockInstance(blockInstanceA); update.tripUpdates = Arrays.asList(tripUpdate); VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update); TimepointPredictionRecord tpr = record.getTimepointPredictions().get(0); long departure = tpr.getTimepointPredictedDepartureTime(); assertEquals(departure, time(7, 33) * 1000); }