FixedRateTimerActionScheduler implements ActionScheduler { @Override public void schedule(final Action action) { if (actionTimerTasks.containsKey(action)) { Logger.v("Already contains action, aborting schedule"); return; } TimerTask taskToExecute = new TimerTask() { @Override public void run() { action.perform(); } }; timer.scheduleAtFixedRate(taskToExecute, DELAY_IN_MILLIS, frequencyInMillis); actionTimerTasks.put(action, taskToExecute); } FixedRateTimerActionScheduler(Timer timer, long frequencyInMillis, Map<Action, TimerTask> actionTimerTasks); @Override void schedule(final Action action); @Override void cancel(Action action); @Override void cancelAll(); @Override boolean isScheduled(Action action);  }
@Test public void executesAction_whenSchedulingAction() { scheduler.schedule(anyAction); timerTask.run(); verify(anyAction).perform(); }
@Test public void recordsAction_whenSchedulingAction() { scheduler.schedule(anyAction); assertThat(actionTimerTasks).containsEntry(anyAction, timerTask); }
@Test public void doesNothing_whenActionAlreadyScheduled() { givenScheduledAction(); scheduler.schedule(anyAction); verifyZeroInteractions(timer); }