PDPModel extends AbstractModel<PDPObject> implements TickListener { public abstract void pickup(Vehicle vehicle, Parcel parcel, TimeLapse time);  @Override final boolean register(PDPObject object); abstract ImmutableSet<Parcel> getContents(Container container); abstract double getContentsSize(Container container); abstract double getContainerCapacity(Container container); abstract void pickup(Vehicle vehicle, Parcel parcel, TimeLapse time); abstract void drop(Vehicle vehicle, Parcel parcel, TimeLapse time); abstract void deliver(Vehicle vehicle, Parcel parcel, TimeLapse time); abstract void addParcelIn(Container container, Parcel parcel); abstract Collection<Parcel> getParcels(ParcelState state); abstract Collection<Parcel> getParcels(ParcelState... states); abstract Set<Vehicle> getVehicles(); abstract ParcelState getParcelState(Parcel parcel); abstract VehicleState getVehicleState(Vehicle vehicle); abstract PDPModel.VehicleParcelActionInfo getVehicleActionInfo(
      Vehicle vehicle); abstract EventAPI getEventAPI(); abstract boolean containerContains(Container container, Parcel parcel); abstract TimeWindowPolicy getTimeWindowPolicy(); abstract void service(Vehicle vehicle, Parcel parcel, TimeLapse time);  }
@Test public void testPickup() { final Parcel pack1 = Parcel.builder(new Point(1, 1), new Point(2, 2)) .neededCapacity(2d) .build(); final Vehicle truck = new TestVehicle( VehicleDTO.builder() .startPosition(new Point(1, 1)) .capacity(10) .speed(1.0) .build()); model.register(pack1); model.register(truck); rm.register(pack1); rm.register(truck); truck.tick(TimeLapseFactory.create(0, 10000)); assertEquals(0, model.getContentsSize(truck), EPSILON); assertTrue(model.getContents(truck).isEmpty()); assertEquals(ParcelState.AVAILABLE, model.getParcelState(pack1)); assertEquals(VehicleState.IDLE, model.getVehicleState(truck)); model.pickup(truck, pack1, TimeLapseFactory.create(0, 10000)); assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack1)); assertEquals(VehicleState.IDLE, model.getVehicleState(truck)); assertFalse(rm.containsObject(pack1)); assertTrue(model.containerContains(truck, pack1)); assertEquals(2, model.getContentsSize(truck), EPSILON); assertTrue(model.getContents(truck).contains(pack1)); assertEquals(1, model.getContents(truck).size()); final Parcel pack2 = Parcel.builder(new Point(1, 2), new Point(2, 2)) .serviceDuration(100L) .neededCapacity(2d) .build(); model.register(pack2); rm.register(pack2); rm.followPath(truck, newLinkedList(asList(new Point(1, 2))), TimeLapseFactory.create(0, 3600000)); assertEquals(new Point(1, 2), rm.getPosition(truck)); assertEquals(new Point(1, 2), rm.getPosition(pack2)); assertEquals(ParcelState.AVAILABLE, model.getParcelState(pack2)); assertEquals(VehicleState.IDLE, model.getVehicleState(truck)); model.pickup(truck, pack2, TimeLapseFactory.create(0, 40)); assertFalse(rm.containsObject(pack2)); final PickupAction action = (PickupAction) model .getVehicleActionInfo(truck); assertFalse(action.isDone()); assertEquals(60, action.timeNeeded()); assertEquals(ParcelState.PICKING_UP, model.getParcelState(pack2)); assertEquals(VehicleState.PICKING_UP, model.getVehicleState(truck)); model.continuePreviousActions(truck, TimeLapseFactory.create(0, 40)); assertFalse(action.isDone()); assertEquals(20, action.timeNeeded()); assertEquals(ParcelState.PICKING_UP, model.getParcelState(pack2)); assertEquals(VehicleState.PICKING_UP, model.getVehicleState(truck)); final TimeLapse tl = TimeLapseFactory.create(0, 40); model.continuePreviousActions(truck, tl); assertTrue(action.isDone()); assertEquals(0, action.timeNeeded()); assertEquals(20, tl.getTimeLeft()); assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack2)); assertEquals(VehicleState.IDLE, model.getVehicleState(truck)); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail1() { final Vehicle truck = new TestVehicle( VehicleDTO.builder().build()); model.pickup(truck, null, TimeLapseFactory.create(0, 1)); }