@Test
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
Shipment shipment = mock(Shipment.class);
Capacity capacity = Capacity.Builder.newInstance().build();
when(shipment.getSize()).thenReturn(capacity);
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
when(vehicle.isReturnToDepot()).thenReturn(true);
when(vehicle.getId()).thenReturn("vehId");
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
//start - pick(shipment) - del(shipment) - end
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
InsertionData iData = mock(InsertionData.class);
when(iData.getPickupInsertionIndex()).thenReturn(2);
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
when(iData.getSelectedVehicle()).thenReturn(vehicle);
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
inserter.insertJob(shipmentToInsert, iData, route);
assertEquals(4,route.getTourActivities().getActivities().size());
assertEquals(route.getTourActivities().getActivities().get(2).getLocationId(),shipmentToInsert.getPickupLocationId());
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocationId());
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
}