Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
simplify assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Aug 14, 2024
1 parent 37ffad7 commit a1024e0
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

package org.matsim.freight.logistics.examples.requirementsChecking;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
Expand Down Expand Up @@ -203,11 +204,11 @@ public void initialize() {
public void testAssignerRequirements() {
for (Id<LspShipment> shipmentId : blueChain.getLspShipmentIds()) {
LspShipment shipment = LSPUtils.findLspShipment(blueChain.getLSP(), shipmentId);
assertTrue(shipment.getRequirements().iterator().next() instanceof BlueRequirement);
assertInstanceOf(BlueRequirement.class, shipment.getRequirements().iterator().next());
}
for (Id<LspShipment> shipmentId : redChain.getLspShipmentIds()) {
LspShipment shipment = LSPUtils.findLspShipment(redChain.getLSP(), shipmentId);
assertTrue(shipment.getRequirements().iterator().next() instanceof RedRequirement);
assertInstanceOf(RedRequirement.class, shipment.getRequirements().iterator().next());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

package org.matsim.freight.logistics.examples.simulationTrackers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -58,6 +55,8 @@
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;

import static org.junit.jupiter.api.Assertions.*;

public class CollectionTrackerTest {
private static final Logger log = LogManager.getLogger(CollectionTrackerTest.class);
@RegisterExtension
Expand Down Expand Up @@ -209,7 +208,7 @@ public void testCollectionTracker() {

assertEquals(1, logisticChain.getSimulationTrackers().size());
LSPSimulationTracker<LogisticChain> tracker = logisticChain.getSimulationTrackers().iterator().next();
assertTrue(tracker instanceof LinearCostTracker);
assertInstanceOf(LinearCostTracker.class, tracker);
LinearCostTracker linearTracker = (LinearCostTracker) tracker;
double totalScheduledCosts = 0;
double totalTrackedCosts = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void testCollectionLSPScheduling() {
assertEquals(2, shipment.getSimulationTrackers().size());
ArrayList<EventHandler> eventHandlers = new ArrayList<>(shipment.getSimulationTrackers());

assertTrue(eventHandlers.getFirst() instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst());
LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst();
assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -205,7 +205,7 @@ public void testCollectionLSPScheduling() {
assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(endHandler.getResourceId(), collectionLSP.getResources().iterator().next().getId());

assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1));
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void testCompletedLSPScheduling() {

assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size());
ArrayList<EventHandler> eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers());
assertTrue(eventHandlers.getFirst() instanceof TransshipmentHubTourEndEventHandler);
assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst());
TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst();
Iterator<Entry<CarrierService, TransshipmentHubTourEndEventHandler.TransshipmentHubEventHandlerPair>> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator();

Expand All @@ -455,7 +455,7 @@ public void testCompletedLSPScheduling() {

assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size());
eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers());
assertTrue(eventHandlers.getFirst() instanceof TransshipmentHubTourEndEventHandler);
assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst());
reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst();
iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator();

Expand Down Expand Up @@ -486,7 +486,7 @@ public void testCompletedLSPScheduling() {
ArrayList<LspShipmentPlanElement> planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values());
planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator());

assertTrue(eventHandlers.getFirst() instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst());
LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst();
assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -503,7 +503,7 @@ public void testCompletedLSPScheduling() {
assertSame(endHandler.getResourceId(), resources.getFirst().getId());

//CollectionServiceEnd
assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1));
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -520,7 +520,7 @@ public void testCompletedLSPScheduling() {
assertSame(serviceHandler.getResourceId(), resources.getFirst().getId());

//MainRunStart
assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler);
assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2));
LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2);
assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
Expand All @@ -538,7 +538,7 @@ public void testCompletedLSPScheduling() {
assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId());

//MainRunEnd
assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3));
LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3);
assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
Expand All @@ -556,7 +556,7 @@ public void testCompletedLSPScheduling() {
assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId());

//DistributionRunStart
assertTrue(eventHandlers.get(4) instanceof LSPTourStartEventHandler);
assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(4));
LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4);
assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo());
assertEquals(lspTourStartEventHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
Expand All @@ -574,7 +574,7 @@ public void testCompletedLSPScheduling() {
assertSame(lspTourStartEventHandler.getResourceId(), resources.get(4).getId());

//DistributionServiceStart
assertTrue(eventHandlers.get(5) instanceof DistributionServiceStartEventHandler);
assertInstanceOf(DistributionServiceStartEventHandler.class, eventHandlers.get(5));
DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5);
assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo());
assertEquals(distributionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void testFirstReloadLSPScheduling() {

assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size());
ArrayList<EventHandler> eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers());
assertTrue(eventHandlers.getFirst() instanceof TransshipmentHubTourEndEventHandler);
assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst());
TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst();

for (Entry<CarrierService, TransshipmentHubTourEndEventHandler.TransshipmentHubEventHandlerPair> entry : reloadEventHandler.getServicesWaitedFor().entrySet()) {
Expand Down Expand Up @@ -281,7 +281,7 @@ public void testFirstReloadLSPScheduling() {
eventHandlers = new ArrayList<>(shipment.getSimulationTrackers());
ArrayList<LspShipmentPlanElement> planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values());

assertTrue(eventHandlers.getFirst() instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst());
LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst();
assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -293,7 +293,7 @@ public void testFirstReloadLSPScheduling() {
assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(endHandler.getResourceId(), lsp.getResources().iterator().next().getId());

assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1));
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void testMainRunLSPScheduling() {

assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size());
ArrayList<EventHandler> eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers());
assertTrue(eventHandlers.getFirst() instanceof TransshipmentHubTourEndEventHandler);
assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst());
TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst();

for (Entry<CarrierService, TransshipmentHubTourEndEventHandler.TransshipmentHubEventHandlerPair> entry : reloadEventHandler.getServicesWaitedFor().entrySet()) {
Expand Down Expand Up @@ -350,7 +350,7 @@ public void testMainRunLSPScheduling() {
ArrayList<LogisticChainElement> solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements());
ArrayList<LSPResource> resources = new ArrayList<>(lsp.getResources());

assertTrue(eventHandlers.getFirst() instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst());
LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst();
assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -367,7 +367,7 @@ public void testMainRunLSPScheduling() {
assertSame(endHandler.getResourceId(), resources.getFirst().getId());

//CollectionServiceEnd
assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1));
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -384,7 +384,7 @@ public void testMainRunLSPScheduling() {
assertSame(serviceHandler.getResourceId(), resources.getFirst().getId());

//MainRunTourStart
assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler);
assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2));
LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2);
assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
Expand All @@ -402,7 +402,7 @@ public void testMainRunLSPScheduling() {
assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId());

//MainRunTourEnd
assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3));
LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3);
assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId);
assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testCollectionLSPScheduling() {
assertEquals(2, shipment.getSimulationTrackers().size());
ArrayList<EventHandler> eventHandlers = new ArrayList<>(shipment.getSimulationTrackers());

assertTrue(eventHandlers.getFirst() instanceof LSPTourEndEventHandler);
assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst());
LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst();
assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand All @@ -208,7 +208,7 @@ public void testCollectionLSPScheduling() {
assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId());
assertSame(endHandler.getResourceId(), collectionLSP.getResources().iterator().next().getId());

assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler);
assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1));
CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1);
assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom());
assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize());
Expand Down
Loading

0 comments on commit a1024e0

Please sign in to comment.