ScenarioController extends AbstractModel<StopModel> implements TickListener { public static Builder builder(Scenario scenario) { return Builder.create(scenario); } ScenarioController(SimulatorAPI sim, ClockController c, Scenario s,
      ImmutableMap<Class<? extends TimedEvent>, TimedEventHandler<?>> m,
      int t); EventAPI getEventAPI(); ProblemClass getScenarioProblemClass(); String getScenarioId(); boolean isScenarioFinished(); @Override void tick(TimeLapse timeLapse); @Override void afterTick(TimeLapse timeLapse); @Override boolean register(StopModel element); @Deprecated @Override boolean unregister(StopModel element); @Override U get(Class<U> type); static Builder builder(Scenario scenario);  }
@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(); }
@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(); }
@Test public void testStopCondition() { final Simulator sim = Simulator .builder() .setTickLength(1L) .addModel( ScenarioController .builder(scenario) .withEventHandler(EventA.class, new NopHandler<EventA>()) .withEventHandler(EventB.class, new NopHandler<EventB>()) .withEventHandler(EventC.class, new NopHandler<EventC>()) .withAndStopCondition(StopConditions.alwaysTrue())) .build(); sim.start(); assertThat(sim.getCurrentTime()).isEqualTo(1L); final Simulator sim2 = Simulator .builder() .setTickLength(1L) .addModel( ScenarioController .builder(scenario) .withEventHandler(EventA.class, new NopHandler<EventA>()) .withEventHandler(EventB.class, new NopHandler<EventB>()) .withEventHandler(EventC.class, new NopHandler<EventC>()) .withAndStopCondition(StopConditions.limitedTime(100))) .build(); sim2.start(); assertThat(sim2.getCurrentTime()).isEqualTo(101L); }