@Test public void testRemoveCharacterEvents() throws Exception { final Character chara = MockFactory.mockCharacter(); final TimedEvent event2 = MockFactory.mockTimedEvent(chara); final TimedEvent event3 = MockFactory.mockTimedEvent(chara); event = MockFactory.mockTimedEvent(chara); service.addEvent(chara, event, 50L, 50L, 300L); service.addEvent(chara, event2, 100L); service.addEvent(chara, event3, 200L); Thread.sleep(55L); service.removeCharacterEvents(chara); verify(event).execute(); verifyZeroInteractions(event2, event3); }
@Override public void removeCharacterEvents(Character chara) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.remove(chara); if (characterEvents == null) { return; } synchronized (characterEvents) { Iterator<TimedEvent> it = characterEvents.keySet().iterator(); while (it.hasNext()) { characterEvents.get(it.next()).cancel(); it.remove(); } } }
TimedEventsServiceImpl implements TimedEventsService { @Override public void removeCharacterEvents(Character chara) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.remove(chara); if (characterEvents == null) { return; } synchronized (characterEvents) { Iterator<TimedEvent> it = characterEvents.keySet().iterator(); while (it.hasNext()) { characterEvents.get(it.next()).cancel(); it.remove(); } } } }
TimedEventsServiceImpl implements TimedEventsService { @Override public void removeCharacterEvents(Character chara) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.remove(chara); if (characterEvents == null) { return; } synchronized (characterEvents) { Iterator<TimedEvent> it = characterEvents.keySet().iterator(); while (it.hasNext()) { characterEvents.get(it.next()).cancel(); it.remove(); } } }  }
TimedEventsServiceImpl implements TimedEventsService { @Override public void removeCharacterEvents(Character chara) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.remove(chara); if (characterEvents == null) { return; } synchronized (characterEvents) { Iterator<TimedEvent> it = characterEvents.keySet().iterator(); while (it.hasNext()) { characterEvents.get(it.next()).cancel(); it.remove(); } } }  @Override void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor); @Override void addEvent(Character chara, TimedEvent event, long delay); @Override void removeCharacterEvents(Character chara); @Override void removeEvent(TimedEvent event); }
TimedEventsServiceImpl implements TimedEventsService { @Override public void removeCharacterEvents(Character chara) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.remove(chara); if (characterEvents == null) { return; } synchronized (characterEvents) { Iterator<TimedEvent> it = characterEvents.keySet().iterator(); while (it.hasNext()) { characterEvents.get(it.next()).cancel(); it.remove(); } } }  @Override void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor); @Override void addEvent(Character chara, TimedEvent event, long delay); @Override void removeCharacterEvents(Character chara); @Override void removeEvent(TimedEvent event);  }