/** * Tests that a not handled event results in a {@link IllegalStateException}. */ @Test public void testEventNotHandled() { final ScenarioController.Builder b = ScenarioController.builder(scenario) .withNumberOfTicks(3); boolean fail = false; try { b.build(dependencyProvider); } catch (final IllegalStateException e) { assertThat(e.getMessage()).containsMatch("No handler found for event"); fail = true; } assertThat(fail).isTrue(); }
/** * Tests that handling an interface is rejected. */ @Test public void testHandleInterface() { boolean fail = false; try { ScenarioController.builder(scenario) .withEventHandler(TimedEvent.class, new NopHandler<>()).toString(); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()).containsMatch("Must handle a concrete class"); } assertThat(fail).isTrue(); }
ScenarioController.builder( scenario) .withIgnoreRedundantHandlers(true)
ScenarioController.builder( scenario) .withIgnoreRedundantHandlers(true)
.addModel( ScenarioController .builder(scenario) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler())
.addModel( ScenarioController .builder(scenario) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler())
.setTimeUnit(SI.SECOND) .addModel( ScenarioController.builder(scenario) .withNumberOfTicks(-1) .withEventHandler(EventA.class, (NopHandler<EventA>) handler)
public static void main(String[] args) throws IOException { for (int i = 0; i < 100; i++) { final FabriRechtScenario scenario = FabriRechtParser.fromJson(Files .toString(new File("files/test/fabri-recht/lc101.scenario"), Charsets.UTF_8), 8, 20); Simulator.builder() .addModel( ScenarioController.builder(scenario) .withEventHandler(AddVehicleEvent.class, new TimedEventHandler<AddVehicleEvent>() { @Override public void handleTimedEvent(AddVehicleEvent event, SimulatorAPI simulator) { simulator.register(new Truck(event.getVehicleDTO())); } })) .addModel( View.builder() .with(PlaneRoadModelRenderer.builder()) .with(RoadUserRenderer.builder()) .with(PDPModelRenderer.builder()) .withSpeedUp(50) .withAutoClose() .withAutoPlay()) .build().start(); } } }
.setTimeUnit(SI.SECOND) .addModel( ScenarioController.builder(scenario) .withEventHandler(EventA.class, aHandler) .withEventHandler(EventB.class, bHandler)
.addModel( ScenarioController .builder(scenario) .withEventHandler(EventA.class, new NopHandler<EventA>()) .withEventHandler(EventB.class, new NopHandler<EventB>()) .addModel( ScenarioController .builder(scenario) .withEventHandler(EventA.class, new NopHandler<EventA>()) .withEventHandler(EventB.class, new NopHandler<EventB>())
.setTimeUnit(SI.SECOND) .addModel( ScenarioController.builder(scenario) .withEventHandler(EventA.class, (NopHandler<EventA>) handler) .withEventHandler(EventB.class, (NopHandler<EventB>) handler)
.setTimeUnit(SI.SECOND) .addModel( ScenarioController.builder(s) .withNumberOfTicks(1) .withEventHandler(EventA.class, (NopHandler<EventA>) handler)
.addModel( ScenarioController .builder(testScenario) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler())
.addModel( ScenarioController .builder(s) .withEventHandler(AddDepotEvent.class, AddDepotEvent.defaultHandler())
static Simulator.Builder init( TimedEventHandler<AddVehicleEvent> vehicleHandler, Iterable<? extends TimedEvent> events) { final Scenario scenario = Scenario.builder() .addEvent(AddDepotEvent.create(-1, new Point(5, 5))) .addEvent(AddVehicleEvent.create(-1, VehicleDTO.builder().build())) .addEvent(AddVehicleEvent.create(-1, VehicleDTO.builder().build())) .addEvents(events) .build(); final ScenarioController.Builder sb = ScenarioController.builder(scenario) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler()) .withEventHandler(AddVehicleEvent.class, vehicleHandler) .withEventHandler(AddDepotEvent.class, AddDepotEvent.defaultHandler()) .withEventHandler(TimeOutEvent.class, TimeOutEvent.ignoreHandler()) .withOrStopCondition(StatsStopConditions.vehiclesDoneAndBackAtDepot()) .withOrStopCondition(StatsStopConditions.timeOutEvent()); return Simulator.builder() .addModel(PDPRoadModel.builder(RoadModelBuilders.plane()) .withAllowVehicleDiversion(true)) .addModel(DefaultPDPModel.builder()) .addModel(TimeModel.builder() .withRealTime() .withStartInClockMode(ClockMode.SIMULATED) .withTickLength(100)) .addModel(sb) .addModel(StatsTracker.builder()); }
.addModel(ScenarioController.builder(b.build()) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler()) .withEventHandler(TimeOutEvent.class,