@Test public void whenNextStateContainsAlreadyRegistered() { ListenerRegistration w1 = newRegistration(GameState.WAITING); ListenerRegistration wa2 = newRegistration(GameState.WAITING, GameState.ACTIVE); ListenerRegistration a1 = newRegistration(GameState.ACTIVE); List<ListenerRegistration> registrations = new ArrayList<>(Arrays.asList(w1, wa2, a1)); runTest(listenerRegistrationService -> { listenerRegistrationService.gameStateChanged(GameState.WAITING); verify(pluginManager).registerEvents(eq(w1.getListener()), any()); verify(pluginManager).registerEvents(eq(wa2.getListener()), any()); verifyZeroInteractions(listenerUnregister); reset(listenerUnregister, pluginManager); listenerRegistrationService.gameStateChanged(GameState.ACTIVE); verify(pluginManager).registerEvents(eq(a1.getListener()), any()); verify(listenerUnregister, times(1)).unregister(eq(w1.getListener())); verify(listenerUnregister, times(0)).unregister(eq(wa2.getListener())); }, registrations); }
public void gameStateChanged(GameState newState) { Set<Listener> listenersForNewState = recalculateListenersForNewState(newState); this.registerNew(listenersForNewState); }
ListenerRegistrationService { public void gameStateChanged(GameState newState) { Set<Listener> listenersForNewState = recalculateListenersForNewState(newState); this.registerNew(listenersForNewState); } }
ListenerRegistrationService { public void gameStateChanged(GameState newState) { Set<Listener> listenersForNewState = recalculateListenersForNewState(newState); this.registerNew(listenersForNewState); } ListenerRegistrationService(Plugin plugin, PluginManager pluginManager, List<ListenerRegistration> registrationListeners, ListenerUnregister listenerUnregister); }
ListenerRegistrationService { public void gameStateChanged(GameState newState) { Set<Listener> listenersForNewState = recalculateListenersForNewState(newState); this.registerNew(listenersForNewState); } ListenerRegistrationService(Plugin plugin, PluginManager pluginManager, List<ListenerRegistration> registrationListeners, ListenerUnregister listenerUnregister); void gameStateChanged(GameState newState); }
ListenerRegistrationService { public void gameStateChanged(GameState newState) { Set<Listener> listenersForNewState = recalculateListenersForNewState(newState); this.registerNew(listenersForNewState); } ListenerRegistrationService(Plugin plugin, PluginManager pluginManager, List<ListenerRegistration> registrationListeners, ListenerUnregister listenerUnregister); void gameStateChanged(GameState newState);  }