Simulator implements SimulatorAPI { public static Builder builder() { return new Builder(); } Simulator(Builder b); @SuppressWarnings("static-method") @Deprecated boolean register(Model<?> m); @Override void register(Object obj); @Override void unregister(Object o); ImmutableSet<Model<?>> getModels(); ModelProvider getModelProvider(); long getCurrentTime(); long getTimeStep(); void addTickListener(TickListener listener); void removeTickListener(TickListener listener); void start(); void togglePlayPause(); void stop(); void tick(); boolean isPlaying(); @Override RandomGenerator getRandomGenerator(); Unit<Duration> getTimeUnit(); static Builder builder();  }
@Test public void testCircularDependencies() { final Simulator.Builder b = Simulator.builder() .addModel(new CircleA()) .addModel(new CircleB()) .addModel(new CircleC()); boolean fail = false; try { b.build(); } catch (final IllegalArgumentException e) { fail = true; } assertThat(fail).isTrue(); }
@Test public void testUnknownDependency() { final Simulator.Builder b = Simulator.builder() .addModel(new CircleA()); boolean fail = false; try { b.build(); } catch (final IllegalArgumentException e) { fail = true; } assertThat(fail).isTrue(); }
@Test public void testDuplicateProvider() { final Simulator.Builder b = Simulator.builder() .addModel(new DuplicateA()); boolean fail = false; try { b.addModel(new DuplicateB()); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).contains( "provider for class java.lang.Object already exists"); fail = true; } assertThat(fail).isTrue(); }
@Test public void testNopBuilder() { final Simulator.Builder b = Simulator.builder() .addModel(new NopBuilder()) .addModel(new A()) .addModel(new B()); boolean fail = false; try { b.build(); } catch (final IllegalStateException e) { assertThat(e.getMessage()) .containsMatch("dependencies MUST be requested"); fail = true; } assertThat(fail).isTrue(); }
@Test public void testAskTwiceBuilder() { final Simulator.Builder b = Simulator.builder() .addModel(new AskTwiceBuilder()) .addModel(new A()) .addModel(new B()); boolean fail = false; try { b.build(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).containsMatch("is already requested"); fail = true; } assertThat(fail).isTrue(); }
@Test public void testAskWrongTypeBuilder() { final Simulator.Builder b = Simulator.builder() .addModel(new AskWrongTypeBuilder()) .addModel(new A()) .addModel(new B()); boolean fail = false; try { b.build(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).containsMatch("is not a type that"); assertThat(e.getMessage()).containsMatch("declared as a dependency"); fail = true; } assertThat(fail).isTrue(); }
@Test public void testAskWithoutAnyDepsBuilder() { final Simulator.Builder b = Simulator.builder(); boolean fail = false; try { b.addModel(new AskWithoutAnyDepsBuilder()); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).containsMatch( "did not declare any dependencies"); fail = true; } assertThat(fail).isTrue(); }