public void testWithPenalty_whenHavingTwoRegularVehicleAvailablePlusOnePenaltyVehicle_andOneIsLocked_returnTheOtherRegularVehicle() { VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard").build(); PenaltyVehicleType penaltyVehicleType = new PenaltyVehicleType(penaltyType); Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty") .setStartLocationId("loc") .setType(penaltyVehicleType) .build(); Vehicle v3 = VehicleImpl.Builder.newInstance("standard_v3") .setStartLocationId("loc") .setType(penaltyType) .build(); List<Vehicle> vehicles = new ArrayList<Vehicle>(); vehicles.add(v1); vehicles.add(v2); vehicles.add(penalty4standard); vehicles.add(v3); VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(vehicles).createFleetManager(); fleetManager.lock(v1); fleetManager.lock(v2); Collection<Vehicle> availableVehicles = fleetManager.getAvailableVehicles(); assertEquals(1, availableVehicles.size()); assertEquals(v3, availableVehicles.iterator().next()); }
public void testUnlock() { fleetManager.lock(v1); Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles(); assertEquals(1, vehicles.size()); fleetManager.unlock(v1); Collection<Vehicle> vehicles_ = fleetManager.getAvailableVehicles(); assertEquals(2, vehicles_.size()); }
public void testLockTwice() { fleetManager.lock(v1); Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles(); assertEquals(1, vehicles.size()); try { fleetManager.lock(v1); @SuppressWarnings("unused") Collection<Vehicle> vehicles_ = fleetManager.getAvailableVehicles(); assertFalse(true); } catch (IllegalStateException e) { assertTrue(true); } }
public void testWithPenalty_whenHavingOneRegularVehicleAvailable_noPenaltyVehicleIsReturn() { Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty") .setStartLocationId("loc") .setType(VehicleTypeImpl.Builder.newInstance("standard").build()) .build(); List<Vehicle> vehicles = new ArrayList<Vehicle>(); vehicles.add(v1); vehicles.add(v2); vehicles.add(penalty4standard); VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(vehicles).createFleetManager(); Collection<Vehicle> availableVehicles = fleetManager.getAvailableVehicles(); assertEquals(2, availableVehicles.size()); }
@Override public void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) { List<VehicleRoute> routes = new ArrayList<VehicleRoute>(vehicleRoutes); for (VehicleRoute route : routes) { if (route.isEmpty()) { fleetManager.unlock(route.getVehicle()); vehicleRoutes.remove(route); } } }
public void testGetVehiclesWithout() { Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles(v1); assertEquals(v2, vehicles.iterator().next()); assertEquals(1, vehicles.size()); }
public void testGetVehicles() { Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles(); assertEquals(2, vehicles.size()); }