### Question:
ImplicitDispatchTrigger implements EventHandler { @Override public void onEvent(Object event) { if (!(event instanceof TCSObjectEvent)) { return; } TCSObjectEvent objectEvent = (TCSObjectEvent) event; if (objectEvent.getCurrentOrPreviousObjectState() instanceof Vehicle) { checkVehicleChange((Vehicle) objectEvent.getPreviousObjectState(), (Vehicle) objectEvent.getCurrentObjectState()); } } ImplicitDispatchTrigger(Dispatcher dispatcher); @Override void onEvent(Object event);  }### Answer:
@Test public void dispatchWhenIdleAndEnergyLevelChanged() { Vehicle vehicleOld = new Vehicle("someVehicle") .withIntegrationLevel(Vehicle.IntegrationLevel.TO_BE_UTILIZED) .withProcState(Vehicle.ProcState.IDLE) .withState(Vehicle.State.IDLE) .withEnergyLevel(100); Vehicle vehicleNew = vehicleOld.withEnergyLevel(99); listener.onEvent(new TCSObjectEvent(vehicleNew, vehicleOld, TCSObjectEvent.Type.OBJECT_MODIFIED)); verify(dispatcher).dispatch(); }
@Test public void noDispatchWhenNotIdleAndEnergyLevelChanged() { Vehicle vehicleOld = new Vehicle("someVehicle") .withIntegrationLevel(Vehicle.IntegrationLevel.TO_BE_UTILIZED) .withProcState(Vehicle.ProcState.PROCESSING_ORDER) .withState(Vehicle.State.EXECUTING) .withEnergyLevel(100); Vehicle vehicleNew = vehicleOld.withEnergyLevel(99); listener.onEvent(new TCSObjectEvent(vehicleNew, vehicleOld, TCSObjectEvent.Type.OBJECT_MODIFIED)); verify(dispatcher, never()).dispatch(); }
@Test public void dispatchWhenProcStateBecameIdle() { Vehicle vehicleOld = new Vehicle("someVehicle") .withIntegrationLevel(Vehicle.IntegrationLevel.TO_BE_UTILIZED) .withProcState(Vehicle.ProcState.PROCESSING_ORDER) .withState(Vehicle.State.EXECUTING); Vehicle vehicleNew = vehicleOld.withProcState(Vehicle.ProcState.IDLE) .withState(Vehicle.State.IDLE); listener.onEvent(new TCSObjectEvent(vehicleNew, vehicleOld, TCSObjectEvent.Type.OBJECT_MODIFIED)); verify(dispatcher).dispatch(); }
@Test public void dispatchWhenProcStateBecameAwaitingOrder() { Vehicle vehicleOld = new Vehicle("someVehicle") .withIntegrationLevel(Vehicle.IntegrationLevel.TO_BE_UTILIZED) .withProcState(Vehicle.ProcState.PROCESSING_ORDER); Vehicle vehicleNew = vehicleOld.withProcState(Vehicle.ProcState.AWAITING_ORDER); listener.onEvent(new TCSObjectEvent(vehicleNew, vehicleOld, TCSObjectEvent.Type.OBJECT_MODIFIED)); verify(dispatcher).dispatch(); }
@Test public void dispatchWhenOrderSequenceNulled() { Vehicle vehicleOld = new Vehicle("someVehicle") .withIntegrationLevel(Vehicle.IntegrationLevel.TO_BE_UTILIZED) .withOrderSequence(new OrderSequence("someSequence").getReference()); Vehicle vehicleNew = vehicleOld.withOrderSequence(null); listener.onEvent(new TCSObjectEvent(vehicleNew, vehicleOld, TCSObjectEvent.Type.OBJECT_MODIFIED)); verify(dispatcher).dispatch(); }