LayoverFilter implements SiriModuleDeliveryFilter { @Override public AbstractServiceDeliveryStructure filter(ServiceDelivery delivery, AbstractServiceDeliveryStructure moduleDelivery) { if (!(moduleDelivery instanceof VehicleMonitoringDeliveryStructure)) { return moduleDelivery; } VehicleMonitoringDeliveryStructure vm = (VehicleMonitoringDeliveryStructure) moduleDelivery; for (VehicleActivityStructure activity : vm.getVehicleActivity()) { MonitoredVehicleJourney mvj = activity.getMonitoredVehicleJourney(); if (!hasMonitoringError(mvj)) { _layoverService.updateVehicle(activity); } if (mvj.getVehicleRef() != null) { String vehicleRef = mvj.getVehicleRef().getValue(); if (_layoverService.isVehiclePausedAtLayoverLocation(vehicleRef)) { OneBusAwayVehicleActivity vaExtension = new OneBusAwayVehicleActivity(); vaExtension.setLayover(true); ExtensionsStructure extensions = new ExtensionsStructure(); extensions.setAny(vaExtension); activity.setExtensions(extensions); } } } return moduleDelivery; }  void setDataPath(String path); void setLayoverService(LayoverService layoverService); @Override AbstractServiceDeliveryStructure filter(ServiceDelivery delivery,
      AbstractServiceDeliveryStructure moduleDelivery);  }
@Test public void testInLayover() throws JAXBException { ServiceDelivery delivery = constructVehicleActivity(); VehicleMonitoringDeliveryStructure vm = delivery.getVehicleMonitoringDelivery().get(0); VehicleActivityStructure activity = vm.getVehicleActivity().get(0); Mockito.when(_layoverService.isVehiclePausedAtLayoverLocation("123")).thenReturn( true); AbstractServiceDeliveryStructure filtered = _filter.filter(delivery, vm); Mockito.verify(_layoverService).updateVehicle(activity); assertSame(vm, filtered); OneBusAwayVehicleActivity extension = (OneBusAwayVehicleActivity) activity.getExtensions().getAny(); assertTrue(extension.isLayover()); }
@Test public void testNoLayover() throws JAXBException { ServiceDelivery delivery = constructVehicleActivity(); VehicleMonitoringDeliveryStructure vm = delivery.getVehicleMonitoringDelivery().get(0); VehicleActivityStructure activity = vm.getVehicleActivity().get(0); Mockito.when(_layoverService.isVehiclePausedAtLayoverLocation("123")).thenReturn( false); AbstractServiceDeliveryStructure filtered = _filter.filter(delivery, vm); Mockito.verify(_layoverService).updateVehicle(activity); assertSame(vm, filtered); assertNull(activity.getExtensions()); }