From 3966590fc7ce6182cb5c58db20c1440367c7aa62 Mon Sep 17 00:00:00 2001 From: oblonski Date: Wed, 15 Jun 2016 14:06:26 +0200 Subject: [PATCH] replace IllegalStateException with IllegalArgumentException where there is bad input --- .../jsprit/core/problem/Capacity.java | 2 +- .../jsprit/core/problem/Location.java | 2 +- .../core/problem/VehicleRoutingProblem.java | 8 +- .../jsprit/core/problem/io/VrpXMLReader.java | 54 ++++++------ .../jsprit/core/problem/job/Delivery.java | 4 +- .../jsprit/core/problem/job/Pickup.java | 4 +- .../jsprit/core/problem/job/Service.java | 6 +- .../jsprit/core/problem/job/Shipment.java | 8 +- .../problem/solution/route/VehicleRoute.java | 16 ++-- .../route/activity/TimeWindowsImpl.java | 6 +- .../route/activity/TourActivities.java | 4 +- .../core/problem/vehicle/VehicleImpl.java | 12 +-- .../core/problem/vehicle/VehicleTypeImpl.java | 34 ++++---- .../jsprit/core/problem/CapacityTest.java | 2 +- .../jsprit/core/problem/LocationTest.java | 2 +- .../problem/VehicleRoutingProblemTest.java | 6 +- .../jsprit/core/problem/job/DeliveryTest.java | 2 +- .../jsprit/core/problem/job/PickupTest.java | 2 +- .../jsprit/core/problem/job/ServiceTest.java | 10 +-- .../jsprit/core/problem/job/ShipmentTest.java | 14 ++-- .../route/VehicleRouteBuilderTest.java | 8 +- .../route/activity/TestTourActivities.java | 2 +- .../route/activity/TimeWindowsImplTest.java | 6 +- .../core/problem/vehicle/VehicleImplTest.java | 10 +-- .../problem/vehicle/VehicleTypeImplTest.java | 10 +-- .../test/resources/infiniteWriterV2Test.xml | 83 +++++++------------ 26 files changed, 146 insertions(+), 171 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Capacity.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Capacity.java index 134b573f..b9ff90c0 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Capacity.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Capacity.java @@ -97,7 +97,7 @@ public class Capacity { double sumQuotients = 0.0; for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) { if (numerator.get(index) != 0 && denominator.get(index) == 0) { - throw new IllegalStateException("numerator > 0 and denominator = 0. cannot divide by 0"); + throw new IllegalArgumentException("numerator > 0 and denominator = 0. cannot divide by 0"); } else if (numerator.get(index) == 0 && denominator.get(index) == 0) { continue; } else { diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java index 58c33903..0a713935 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java @@ -85,7 +85,7 @@ public final class Location implements HasIndex, HasId { public Location build() { if (id == null && coordinate == null) { - if (index == -1) throw new IllegalStateException("either id or coordinate or index must be set"); + if (index == -1) throw new IllegalArgumentException("either id or coordinate or index must be set"); } if (coordinate != null && id == null) { this.id = coordinate.toString(); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java index 8a69ff21..396a08bc 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java @@ -222,9 +222,9 @@ public class VehicleRoutingProblem { */ public Builder addJob(AbstractJob job) { if (tentativeJobs.containsKey(job.getId())) - throw new IllegalStateException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments"); + throw new IllegalArgumentException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments"); if (!(job instanceof Service || job instanceof Shipment)) - throw new IllegalStateException("job must be either a service or a shipment"); + throw new IllegalArgumentException("job must be either a service or a shipment"); job.setIndex(jobIndexCounter); incJobIndexCounter(); tentativeJobs.put(job.getId(), job); @@ -351,7 +351,7 @@ public class VehicleRoutingProblem { * */ public Builder addVehicle(Vehicle vehicle) { if (!(vehicle instanceof AbstractVehicle)) - throw new IllegalStateException("vehicle must be an AbstractVehicle"); + throw new IllegalArgumentException("vehicle must be an AbstractVehicle"); return addVehicle((AbstractVehicle) vehicle); } @@ -363,7 +363,7 @@ public class VehicleRoutingProblem { */ public Builder addVehicle(AbstractVehicle vehicle) { if(addedVehicleIds.contains(vehicle.getId())){ - throw new IllegalStateException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle."); + throw new IllegalArgumentException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle."); } else addedVehicleIds.add(vehicle.getId()); if (!uniqueVehicles.contains(vehicle)) { diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java index e3ae4ded..fb602a76 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java @@ -193,9 +193,9 @@ public class VrpXMLReader { Driver driver = DriverImpl.noDriver(); String vehicleId = routeConfig.getString("vehicleId"); Vehicle vehicle = getVehicle(vehicleId); - if (vehicle == null) throw new IllegalStateException("vehicle is missing."); + if (vehicle == null) throw new IllegalArgumentException("vehicle is missing."); String start = routeConfig.getString("start"); - if (start == null) throw new IllegalStateException("route start-time is missing."); + if (start == null) throw new IllegalArgumentException("route start-time is missing."); double departureTime = Double.parseDouble(start); VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); @@ -204,7 +204,7 @@ public class VrpXMLReader { List actConfigs = routeConfig.configurationsAt("act"); for (HierarchicalConfiguration actConfig : actConfigs) { String type = actConfig.getString("[@type]"); - if (type == null) throw new IllegalStateException("act[@type] is missing."); + if (type == null) throw new IllegalArgumentException("act[@type] is missing."); double arrTime = 0.; double endTime = 0.; String arrTimeS = actConfig.getString("arrTime"); @@ -221,24 +221,24 @@ public class VrpXMLReader { if (serviceId != null) { Service service = getService(serviceId); if (service == null) - throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in ."); + throw new IllegalArgumentException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in ."); //!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled freezedJobIds.add(serviceId); routeBuilder.addService(service); } else { String shipmentId = actConfig.getString("shipmentId"); if (shipmentId == null) - throw new IllegalStateException("either serviceId or shipmentId is missing"); + throw new IllegalArgumentException("either serviceId or shipmentId is missing"); Shipment shipment = getShipment(shipmentId); if (shipment == null) - throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in ."); + throw new IllegalArgumentException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in ."); freezedJobIds.add(shipmentId); if (type.equals("pickupShipment")) { routeBuilder.addPickup(shipment); } else if (type.equals("deliverShipment")) { routeBuilder.addDelivery(shipment); } else - throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); + throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); } } } @@ -262,20 +262,20 @@ public class VrpXMLReader { Driver driver = DriverImpl.noDriver(); String vehicleId = routeConfig.getString("vehicleId"); Vehicle vehicle = getVehicle(vehicleId); - if (vehicle == null) throw new IllegalStateException("vehicle is missing."); + if (vehicle == null) throw new IllegalArgumentException("vehicle is missing."); String start = routeConfig.getString("start"); - if (start == null) throw new IllegalStateException("route start-time is missing."); + if (start == null) throw new IllegalArgumentException("route start-time is missing."); double departureTime = Double.parseDouble(start); String end = routeConfig.getString("end"); - if (end == null) throw new IllegalStateException("route end-time is missing."); + if (end == null) throw new IllegalArgumentException("route end-time is missing."); VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); routeBuilder.setDepartureTime(departureTime); List actConfigs = routeConfig.configurationsAt("act"); for (HierarchicalConfiguration actConfig : actConfigs) { String type = actConfig.getString("[@type]"); - if (type == null) throw new IllegalStateException("act[@type] is missing."); + if (type == null) throw new IllegalArgumentException("act[@type] is missing."); double arrTime = 0.; double endTime = 0.; String arrTimeS = actConfig.getString("arrTime"); @@ -294,16 +294,16 @@ public class VrpXMLReader { } else { String shipmentId = actConfig.getString("shipmentId"); if (shipmentId == null) - throw new IllegalStateException("either serviceId or shipmentId is missing"); + throw new IllegalArgumentException("either serviceId or shipmentId is missing"); Shipment shipment = getShipment(shipmentId); if (shipment == null) - throw new IllegalStateException("shipment with id " + shipmentId + " does not exist."); + throw new IllegalArgumentException("shipment with id " + shipmentId + " does not exist."); if (type.equals("pickupShipment")) { routeBuilder.addPickup(shipment); } else if (type.equals("deliverShipment")) { routeBuilder.addDelivery(shipment); } else - throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); + throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); } } } @@ -315,7 +315,7 @@ public class VrpXMLReader { String jobId = unassignedJobConfig.getString("[@id]"); Job job = getShipment(jobId); if (job == null) job = getService(jobId); - if (job == null) throw new IllegalStateException("cannot find unassignedJob with id " + jobId); + if (job == null) throw new IllegalArgumentException("cannot find unassignedJob with id " + jobId); solution.getUnassignedJobs().add(job); } @@ -351,15 +351,15 @@ public class VrpXMLReader { List shipmentConfigs = config.configurationsAt("shipments.shipment"); for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) { String id = shipmentConfig.getString("[@id]"); - if (id == null) throw new IllegalStateException("shipment[@id] is missing."); + if (id == null) throw new IllegalArgumentException("shipment[@id] is missing."); String capacityString = shipmentConfig.getString("capacity-demand"); boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)"); if (capacityString == null && !capacityDimensionsExist) { - throw new IllegalStateException("capacity of shipment is not set. use 'capacity-dimensions'"); + throw new IllegalArgumentException("capacity of shipment is not set. use 'capacity-dimensions'"); } if (capacityString != null && capacityDimensionsExist) { - throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); + throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); } Shipment.Builder builder; @@ -475,17 +475,17 @@ public class VrpXMLReader { List serviceConfigs = vrpProblem.configurationsAt("services.service"); for (HierarchicalConfiguration serviceConfig : serviceConfigs) { String id = serviceConfig.getString("[@id]"); - if (id == null) throw new IllegalStateException("service[@id] is missing."); + if (id == null) throw new IllegalArgumentException("service[@id] is missing."); String type = serviceConfig.getString("[@type]"); if (type == null) type = "service"; String capacityString = serviceConfig.getString("capacity-demand"); boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)"); if (capacityString == null && !capacityDimensionsExist) { - throw new IllegalStateException("capacity of service is not set. use 'capacity-dimensions'"); + throw new IllegalArgumentException("capacity of service is not set. use 'capacity-dimensions'"); } if (capacityString != null && capacityDimensionsExist) { - throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); + throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); } Service.Builder builder; @@ -556,15 +556,15 @@ public class VrpXMLReader { List typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type"); for (HierarchicalConfiguration typeConfig : typeConfigs) { String typeId = typeConfig.getString("id"); - if (typeId == null) throw new IllegalStateException("typeId is missing."); + if (typeId == null) throw new IllegalArgumentException("typeId is missing."); String capacityString = typeConfig.getString("capacity"); boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)"); if (capacityString == null && !capacityDimensionsExist) { - throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'"); + throw new IllegalArgumentException("capacity of type is not set. use 'capacity-dimensions'"); } if (capacityString != null && capacityDimensionsExist) { - throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); + throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); } VehicleTypeImpl.Builder typeBuilder; @@ -606,10 +606,10 @@ public class VrpXMLReader { boolean doNotWarnAgain = false; for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) { String vehicleId = vehicleConfig.getString("id"); - if (vehicleId == null) throw new IllegalStateException("vehicleId is missing."); + if (vehicleId == null) throw new IllegalArgumentException("vehicleId is missing."); Builder builder = VehicleImpl.Builder.newInstance(vehicleId); String typeId = vehicleConfig.getString("typeId"); - if (typeId == null) throw new IllegalStateException("typeId is missing."); + if (typeId == null) throw new IllegalArgumentException("typeId is missing."); String vType = vehicleConfig.getString("[@type]"); if (vType != null) { if (vType.equals("penalty")) { @@ -617,7 +617,7 @@ public class VrpXMLReader { } } VehicleType type = types.get(typeId); - if (type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing."); + if (type == null) throw new IllegalArgumentException("vehicleType with typeId " + typeId + " is missing."); builder.setType(type); //read startlocation diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java index dda0df4f..ac0a0857 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java @@ -44,10 +44,10 @@ public class Delivery extends Service { * Builds Delivery. * * @return delivery - * @throws IllegalStateException if neither locationId nor coord is set + * @throws IllegalArgumentException if neither locationId nor coord is set */ public Delivery build() { - if (location == null) throw new IllegalStateException("location is missing"); + if (location == null) throw new IllegalArgumentException("location is missing"); this.setType("delivery"); super.capacity = super.capacityBuilder.build(); super.skills = super.skillBuilder.build(); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Pickup.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Pickup.java index b20e66a9..29771845 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Pickup.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Pickup.java @@ -46,10 +46,10 @@ public class Pickup extends Service { *

Pickup type is "pickup" * * @return pickup - * @throws IllegalStateException if neither locationId nor coordinate has been set + * @throws IllegalArgumentException if neither locationId nor coordinate has been set */ public Pickup build() { - if (location == null) throw new IllegalStateException("location is missing"); + if (location == null) throw new IllegalArgumentException("location is missing"); this.setType("pickup"); super.capacity = super.capacityBuilder.build(); super.skills = super.skillBuilder.build(); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java index 88d7bb33..a6d09176 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java @@ -176,10 +176,10 @@ public class Service extends AbstractJob { * Builds the service. * * @return {@link Service} - * @throws IllegalStateException if neither locationId nor coordinate is set. + * @throws IllegalArgumentException if neither locationId nor coordinate is set. */ public T build() { - if (location == null) throw new IllegalStateException("location is missing"); + if (location == null) throw new IllegalArgumentException("location is missing"); this.setType("service"); capacity = capacityBuilder.build(); skills = skillBuilder.build(); @@ -219,7 +219,7 @@ public class Service extends AbstractJob { * @return builder */ public Builder setPriority(int priority) { - if(priority < 1 || priority > 3) throw new IllegalStateException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed"); + if(priority < 1 || priority > 3) throw new IllegalArgumentException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed"); this.priority = priority; return this; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java index 6e862af9..38ab644d 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java @@ -216,12 +216,12 @@ public class Shipment extends AbstractJob { * Builds the shipment. * * @return shipment - * @throws IllegalStateException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord + * @throws IllegalArgumentException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord * is set */ public Shipment build() { - if (pickupLocation_ == null) throw new IllegalStateException("pickup location is missing"); - if (deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing"); + if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing"); + if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing"); capacity = capacityBuilder.build(); skills = skillBuilder.build(); return new Shipment(this); @@ -276,7 +276,7 @@ public class Shipment extends AbstractJob { * @return builder */ public Builder setPriority(int priority) { - if(priority < 1 || priority > 3) throw new IllegalStateException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed"); + if(priority < 1 || priority > 3) throw new IllegalArgumentException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed"); this.priority = priority; return this; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java index 53074242..b99777a2 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java @@ -242,7 +242,7 @@ public class VehicleRoute { * * @param shipment to be picked up and added to this route * @return the builder - * @throws IllegalStateException if method has already been called with the specified shipment. + * @throws IllegalArgumentException if method has already been called with the specified shipment. */ public Builder addPickup(Shipment shipment) { return addPickup(shipment, shipment.getPickupTimeWindow()); @@ -250,7 +250,7 @@ public class VehicleRoute { public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) { if (openShipments.contains(shipment)) - throw new IllegalStateException("shipment has already been added. cannot add it twice."); + throw new IllegalArgumentException("shipment has already been added. cannot add it twice."); List acts = jobActivityFactory.createActivities(shipment); TourActivity act = acts.get(0); act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart()); @@ -266,7 +266,7 @@ public class VehicleRoute { * * @param shipment to be delivered and add to this vehicleRoute * @return builder - * @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). + * @throws IllegalArgumentException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). */ public Builder addDelivery(Shipment shipment) { return addDelivery(shipment,shipment.getDeliveryTimeWindow()); @@ -280,7 +280,7 @@ public class VehicleRoute { tourActivities.addActivity(act); openShipments.remove(shipment); } else { - throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); + throw new IllegalArgumentException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); } return this; } @@ -290,11 +290,11 @@ public class VehicleRoute { * Builds the route. * * @return {@link VehicleRoute} - * @throws IllegalStateException if there are still shipments that have been picked up though but not delivery. + * @throws IllegalArgumentException if there are still shipments that have been picked up though but not delivery. */ public VehicleRoute build() { if (!openShipments.isEmpty()) { - throw new IllegalStateException("there are still shipments that have not been delivered yet."); + throw new IllegalArgumentException("there are still shipments that have not been delivered yet."); } if (!vehicle.isReturnToDepot()) { if (!tourActivities.isEmpty()) { @@ -419,11 +419,11 @@ public class VehicleRoute { * Returns the departureTime of this vehicle in this route. * * @return departureTime - * @throws IllegalStateException if start is null + * @throws IllegalArgumentException if start is null */ public double getDepartureTime() { if (start == null) - throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead."); + throw new IllegalArgumentException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead."); return start.getEndTime(); } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImpl.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImpl.java index bd9c899e..590f3d89 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImpl.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImpl.java @@ -14,13 +14,13 @@ public class TimeWindowsImpl implements TimeWindows { public void add(TimeWindow timeWindow){ for(TimeWindow tw : timeWindows){ if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){ - throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); + throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); } if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){ - throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); + throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); } if(timeWindow.getStart() <= tw.getStart() && timeWindow.getEnd() >= tw.getEnd()){ - throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); + throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); } } timeWindows.add(timeWindow); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TourActivities.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TourActivities.java index ff2f8e1d..7097818a 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TourActivities.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TourActivities.java @@ -214,11 +214,11 @@ public class TourActivities { *

If act instanceof JobActivity, it adds underlying job also. * * @param act to be added - * @throws IllegalStateException if activity-list already contains act. + * @throws IllegalArgumentException if activity-list already contains act. */ public void addActivity(TourActivity act) { if (tourActivities.contains(act)) - throw new IllegalStateException("act " + act + " already in tour. cannot add act twice."); + throw new IllegalArgumentException("act " + act + " already in tour. cannot add act twice."); tourActivities.add(act); addJob(act); } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java index a82b7a36..40aee535 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java @@ -139,10 +139,10 @@ public class VehicleImpl extends AbstractVehicle { * * @param type the type to be set * @return this builder - * @throws IllegalStateException if type is null + * @throws IllegalArgumentException if type is null */ public Builder setType(VehicleType type) { - if (type == null) throw new IllegalStateException("type cannot be null."); + if (type == null) throw new IllegalArgumentException("type cannot be null."); this.type = type; return this; } @@ -224,22 +224,22 @@ public class VehicleImpl extends AbstractVehicle { * Thus endLocationId can never be null even returnToDepot is false. * * @return vehicle - * @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false) + * @throws IllegalArgumentException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false) * or (endLocationId!=null AND returnToDepot=false) */ public VehicleImpl build() { if (latestArrival < earliestStart) - throw new IllegalStateException("latest arrival of vehicle " + id + " must not be smaller than its start time"); + throw new IllegalArgumentException("latest arrival of vehicle " + id + " must not be smaller than its start time"); if (startLocation != null && endLocation != null) { if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot) - throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory.
" + + throw new IllegalArgumentException("this must not be. you specified both endLocationId and open-routes. this is contradictory.
" + "if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified."); } if (startLocation != null && endLocation == null) { endLocation = startLocation; } if (startLocation == null && endLocation == null) { - throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set"); + throw new IllegalArgumentException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set"); } skills = skillBuilder.build(); return new VehicleImpl(this); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java index eb6165a0..f030749f 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java @@ -91,7 +91,7 @@ public class VehicleTypeImpl implements VehicleType { public static VehicleTypeImpl.Builder newInstance(String id) { - if (id == null) throw new IllegalStateException(); + if (id == null) throw new IllegalArgumentException(); return new Builder(id); } @@ -124,10 +124,10 @@ public class VehicleTypeImpl implements VehicleType { * * @param inMeterPerSeconds * @return this builder - * @throws IllegalStateException if velocity is smaller than zero + * @throws IllegalArgumentException if velocity is smaller than zero */ public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) { - if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero"); + if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero"); this.maxVelo = inMeterPerSeconds; return this; } @@ -139,10 +139,10 @@ public class VehicleTypeImpl implements VehicleType { * * @param fixedCost * @return this builder - * @throws IllegalStateException if fixedCost is smaller than zero + * @throws IllegalArgumentException if fixedCost is smaller than zero */ public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { - if (fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero"); + if (fixedCost < 0.0) throw new IllegalArgumentException("fixed costs cannot be smaller than zero"); this.fixedCost = fixedCost; return this; } @@ -154,10 +154,10 @@ public class VehicleTypeImpl implements VehicleType { * * @param perDistance * @return this builder - * @throws IllegalStateException if perDistance is smaller than zero + * @throws IllegalArgumentException if perDistance is smaller than zero */ public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) { - if (perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero"); + if (perDistance < 0.0) throw new IllegalArgumentException("cost per distance must not be smaller than zero"); this.perDistance = perDistance; return this; } @@ -169,12 +169,12 @@ public class VehicleTypeImpl implements VehicleType { * * @param perTime * @return this builder - * @throws IllegalStateException if costPerTime is smaller than zero + * @throws IllegalArgumentException if costPerTime is smaller than zero * @deprecated use .setCostPerTransportTime(..) instead */ @Deprecated public VehicleTypeImpl.Builder setCostPerTime(double perTime) { - if (perTime < 0.0) throw new IllegalStateException(); + if (perTime < 0.0) throw new IllegalArgumentException(); this.perTime = perTime; return this; } @@ -186,10 +186,10 @@ public class VehicleTypeImpl implements VehicleType { * * @param perTime * @return this builder - * @throws IllegalStateException if costPerTime is smaller than zero + * @throws IllegalArgumentException if costPerTime is smaller than zero */ public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) { - if (perTime < 0.0) throw new IllegalStateException(); + if (perTime < 0.0) throw new IllegalArgumentException(); this.perTime = perTime; return this; } @@ -201,10 +201,10 @@ public class VehicleTypeImpl implements VehicleType { * * @param perWaitingTime * @return this builder - * @throws IllegalStateException if costPerTime is smaller than zero + * @throws IllegalArgumentException if costPerTime is smaller than zero */ public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) { - if (perWaitingTime < 0.0) throw new IllegalStateException(); + if (perWaitingTime < 0.0) throw new IllegalArgumentException(); this.perWaitingTime = perWaitingTime; return this; } @@ -233,12 +233,12 @@ public class VehicleTypeImpl implements VehicleType { * @param dimVal * @return the builder * @throws IllegalArgumentException if dimVal < 0 - * @throws IllegalStateException if capacity dimension is already set + * @throws IllegalArgumentException if capacity dimension is already set */ public Builder addCapacityDimension(int dimIndex, int dimVal) { if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (capacityDimensions != null) - throw new IllegalStateException("either build your dimension with build your dimensions with " + + throw new IllegalArgumentException("either build your dimension with build your dimensions with " + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "You used both methods."); dimensionAdded = true; @@ -255,11 +255,11 @@ public class VehicleTypeImpl implements VehicleType { * * @param capacity * @return this builder - * @throws IllegalStateException if capacityDimension has already been added + * @throws IllegalArgumentException if capacityDimension has already been added */ public Builder setCapacityDimensions(Capacity capacity) { if (dimensionAdded) - throw new IllegalStateException("either build your dimension with build your dimensions with " + + throw new IllegalArgumentException("either build your dimension with build your dimensions with " + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "You used both methods."); this.capacityDimensions = capacity; diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/CapacityTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/CapacityTest.java index 946e87ad..3a1212b6 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/CapacityTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/CapacityTest.java @@ -349,7 +349,7 @@ public class CapacityTest { assertEquals(0.0, Capacity.divide(cap1, cap2), 0.001); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenDividingByAZeroDim_itShouldThrowException() { Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build(); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java index 97092199..56308a96 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java @@ -45,7 +45,7 @@ public class LocationTest { Location l = Location.Builder.newInstance().setIndex(-1).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenCoordinateAndIdAndIndexNotSet_throwException() { Location l = Location.Builder.newInstance().build(); } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblemTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblemTest.java index b88cfefc..832430d8 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblemTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblemTest.java @@ -303,7 +303,7 @@ public class VehicleRoutingProblemTest { return Location.Builder.newInstance().setId(i).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenAddingVehiclesWithSameId_itShouldThrowException(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); @@ -453,7 +453,7 @@ public class VehicleRoutingProblemTest { } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenAddingTwoServicesWithTheSameId_itShouldThrowException() { Service service1 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); Service service2 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); @@ -463,7 +463,7 @@ public class VehicleRoutingProblemTest { @SuppressWarnings("UnusedDeclaration") VehicleRoutingProblem vrp = vrpBuilder.build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenAddingTwoShipmentsWithTheSameId_itShouldThrowException() { Shipment shipment1 = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pick").build()) .setDeliveryLocation(Location.newInstance("del")).build(); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java index 304ee13c..fc5ad310 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.*; public class DeliveryTest { - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() { Delivery.Builder.newInstance("p").build(); } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java index 9482722f..ad88fd22 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.*; public class PickupTest { - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() { Pickup.Builder.newInstance("p").build(); } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java index 8ed72c02..9cf5666b 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java @@ -124,7 +124,7 @@ public class ServiceTest { assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); } - @Test(expected=IllegalStateException.class) + @Test(expected=IllegalArgumentException.class) public void whenSettingNeitherLocationIdNorCoord_throwsException(){ @SuppressWarnings("unused") Service s = Service.Builder.newInstance("s").build(); @@ -219,7 +219,7 @@ public class ServiceTest { assertEquals(2,s.getTimeWindows().size()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenMultipleTWOverlap_throwEx(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) .addTimeWindow(TimeWindow.newInstance(0.,10.)) @@ -227,7 +227,7 @@ public class ServiceTest { .setName("name").build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenMultipleTWOverlap2_throwEx(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) .addTimeWindow(TimeWindow.newInstance(20., 30.)) @@ -256,14 +256,14 @@ public class ServiceTest { Assert.assertEquals(2, s.getPriority()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) .setPriority(30).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException2(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) .setPriority(0).build(); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java index 814f271f..8e669425 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java @@ -86,13 +86,13 @@ public class ShipmentTest { assertNotNull(builder); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenNeitherPickupLocationIdNorPickupCoord_itThrowsException() { @SuppressWarnings("unused") Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenNeitherDeliveryLocationIdNorDeliveryCoord_itThrowsException() { @SuppressWarnings("unused") Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); @@ -105,7 +105,7 @@ public class ShipmentTest { assertEquals("pickLoc", s.getPickupLocation().getId()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenPickupLocationIsNull_itThrowsException() { @SuppressWarnings("unused") Shipment.Builder builder = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId(null).build()); @@ -253,7 +253,7 @@ public class ShipmentTest { assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2))); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() { Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5) .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); @@ -290,7 +290,7 @@ public class ShipmentTest { assertThat(s.getPickupTimeWindows(), hasItem(is(tw2))); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() { Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5) .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); @@ -408,7 +408,7 @@ public class ShipmentTest { Assert.assertEquals(2, s.getPriority()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) .setDeliveryLocation(Location.newInstance("loc")) @@ -416,7 +416,7 @@ public class ShipmentTest { } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException2(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) .setDeliveryLocation(Location.newInstance("loc")) diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java index 9aec7547..75bd90af 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java @@ -32,14 +32,14 @@ import static org.mockito.Mockito.when; public class VehicleRouteBuilderTest { - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenDeliveryIsAddedBeforePickup_throwsException() { Shipment s = mock(Shipment.class); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); builder.addDelivery(s); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenPickupIsAddedTwice_throwsException() { Shipment s = mock(Shipment.class); when(s.getSize()).thenReturn(Capacity.Builder.newInstance().build()); @@ -49,7 +49,7 @@ public class VehicleRouteBuilderTest { builder.addPickup(s); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException() { Shipment s = mock(Shipment.class); Capacity capacity = Capacity.Builder.newInstance().build(); @@ -62,7 +62,7 @@ public class VehicleRouteBuilderTest { builder.addDelivery(s); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException() { Shipment s = mock(Shipment.class); Capacity capacity = Capacity.Builder.newInstance().build(); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TestTourActivities.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TestTourActivities.java index f46dd17d..1e1b6164 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TestTourActivities.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TestTourActivities.java @@ -45,7 +45,7 @@ public class TestTourActivities { assertTrue(tour.servesJob(service)); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenAddingServiceActTwice_anExceptionIsThrown() { assertFalse(tour.servesJob(service)); tour.addActivity(act); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImplTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImplTest.java index 1f28e94b..7c512668 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImplTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/solution/route/activity/TimeWindowsImplTest.java @@ -7,21 +7,21 @@ import org.junit.Test; */ public class TimeWindowsImplTest { - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void overlappingTW_shouldThrowException(){ TimeWindowsImpl tws = new TimeWindowsImpl(); tws.add(TimeWindow.newInstance(50, 100)); tws.add(TimeWindow.newInstance(90,150)); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void overlappingTW2_shouldThrowException(){ TimeWindowsImpl tws = new TimeWindowsImpl(); tws.add(TimeWindow.newInstance(50, 100)); tws.add(TimeWindow.newInstance(40,150)); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void overlappingTW3_shouldThrowException(){ TimeWindowsImpl tws = new TimeWindowsImpl(); tws.add(TimeWindow.newInstance(50, 100)); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java index fba002ed..eea9a172 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java @@ -30,7 +30,7 @@ import static org.junit.Assert.*; public class VehicleImplTest { - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException() { @SuppressWarnings("unused") Vehicle v = VehicleImpl.Builder.newInstance("v").build(); @@ -133,7 +133,7 @@ public class VehicleImplTest { assertEquals("startLoc", v.getStartLocation().getId()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenStartLocationIsNull_itThrowsException() { @SuppressWarnings("unused") Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build(); @@ -185,13 +185,13 @@ public class VehicleImplTest { assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() { @SuppressWarnings("unused") Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() { @SuppressWarnings("unused") Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build(); @@ -209,7 +209,7 @@ public class VehicleImplTest { assertEquals(v.getStartLocation().getCoordinate().toString(), v.getEndLocation().getId()); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException() { @SuppressWarnings("unused") Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build(); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java index 9fae1c1c..c11345ab 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java @@ -85,7 +85,7 @@ public class VehicleTypeImplTest { VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").addCapacityDimension(0, -10).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenBuildingTypeWithNullId_throwIllegalStateException() { @SuppressWarnings("unused") VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null).addCapacityDimension(0, 10).build(); @@ -99,13 +99,13 @@ public class VehicleTypeImplTest { } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenMaxVelocitySmallerThanZero_itShouldThrowException() { @SuppressWarnings("unused") VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build(); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenFixedCostsSmallerThanZero_itShouldThrowException() { @SuppressWarnings("unused") VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build(); @@ -116,7 +116,7 @@ public class VehicleTypeImplTest { assertEquals(10.0, type.getVehicleCostParams().fix, 0.0); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException() { @SuppressWarnings("unused") VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build(); @@ -127,7 +127,7 @@ public class VehicleTypeImplTest { assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit, 0.0); } - @Test(expected = IllegalStateException.class) + @Test(expected = IllegalArgumentException.class) public void whenPerTimeCostsSmallerThanZero_itShouldThrowException() { @SuppressWarnings("unused") VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build(); diff --git a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml index c7b5a449..b34bf776 100644 --- a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml +++ b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml @@ -2,7 +2,7 @@ - INFINITE + FINITE @@ -20,6 +20,21 @@ true + + v2 + vehType2 + + loc + + + loc + + + 0.0 + 1.7976931348623157E308 + + true + @@ -35,58 +50,18 @@ 0.0 + + vehType2 + + 200 + + + 0.0 + 1.0 + + 0.0 + 0.0 + + - - - - loc - - - 1 - - 2.0 - - - 0.0 - 1.7976931348623157E308 - - - - - - loc2 - - - 1 - - 4.0 - - - 0.0 - 1.7976931348623157E308 - - - - - - - 10.0 - - - noDriver - v1 - 0.0 - - 1 - 0.0 - 0.0 - - 0.0 - - - - - - -