SourceTrackingEventScheduler extends TypedEventScheduler { @Override public Cancelable doAt(double time, Runnable r, String description, boolean isDaemon) { MutableCancelableHolder cancelableHolder = new MutableCancelableHolder(r, description); doAt(time, isDaemon, cancelableHolder); return cancelableHolder; } SourceTrackingEventScheduler(SourceSchedulerTracker tracker, EventSchedulerType type, SimpleDiscreteEventScheduler backingScheduler); SourceTrackingEventScheduler createSibling(EventSchedulerType type); void delayExecutionUntil(double delayEndTime); @Override boolean hasOnlyDaemonEvents(); @Override void cancel(Event e); @Override void stop(); @Override TimeProvider getTimeProvider(); @Override long getThreadId(); @Override double getMinimumTimeDelta(); @Override Cancelable doNow(Runnable r, String description); @Override Cancelable doAt(double time, Runnable r, String description, boolean isDaemon); @Override boolean isThreadHandoverRequired();  }
@Test void whenEventExecuted_thenCorrectSchedulerTypeSet() { List<EventSchedulerType> observedTypes = new ArrayList<>(); threadOneScheduler.doAt(50, () -> observedTypes.add(tracker.getActiveSchedulerType()), ""); threadTwoScheduler.doAt(100, () -> observedTypes.add(tracker.getActiveSchedulerType()), ""); threadOneScheduler.doAt(150, () -> observedTypes.add(tracker.getActiveSchedulerType()), ""); backingScheduler.unPause(); List<TestSchedulerType> expectedTypes = new ArrayList<>(); expectedTypes.add(TestSchedulerType.T1); expectedTypes.add(TestSchedulerType.T2); expectedTypes.add(TestSchedulerType.T1); Assertions.assertEquals(expectedTypes, observedTypes); }
@Test void whenEventCancelled_thenEventNotExecuted() { List<Boolean> executed = new ArrayList<>(); executed.add(false); Cancelable cancelable = threadOneScheduler.doAt(50, () -> executed.set(0, true), ""); threadOneScheduler.doAt(25d, cancelable::cancel, ""); backingScheduler.unPause(); Assertions.assertFalse(executed.get(0), "event executed after cancellation"); }