FixedRateTimerActionScheduler implements ActionScheduler { @Override public void cancel(Action action) { if (actionTimerTasks.containsKey(action)) { TimerTask timerTask = actionTimerTasks.get(action); timerTask.cancel(); actionTimerTasks.remove(action); } } 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 cancelTimerTask_whenCancellingSpecificAction() { TimerTask timerTask = mock(TimerTask.class); actionTimerTasks.put(anyAction, timerTask); scheduler.cancel(anyAction); verify(timerTask).cancel(); }
@Test public void removeTimerTask_whenCancellingSpecificAction() { TimerTask timerTask = mock(TimerTask.class); actionTimerTasks.put(anyAction, timerTask); ActionScheduler.Action additionalAction = mock(ActionScheduler.Action.class); TimerTask additionalTimerTask = mock(TimerTask.class); actionTimerTasks.put(anyAction, timerTask); actionTimerTasks.put(additionalAction, additionalTimerTask); scheduler.cancel(anyAction); assertThat(actionTimerTasks).doesNotContainEntry(anyAction, timerTask); assertThat(actionTimerTasks).containsEntry(additionalAction, additionalTimerTask); }