### Question:
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);  }### Answer:
@Test public void whenOnlyOneState() { List<ListenerRegistration> registrations = new ArrayList<>(); registrations.add(newRegistration(GameState.WAITING)); registrations.add(newRegistration(GameState.WAITING)); runTest(listenerRegistrationService -> { listenerRegistrationService.gameStateChanged(GameState.WAITING); verify(pluginManager, times(2)).registerEvents(any(), any()); verifyZeroInteractions(listenerUnregister); }, registrations); }
@Test public void whenMultipleStates() { ListenerRegistration w1 = newRegistration(GameState.WAITING); ListenerRegistration w2 = newRegistration(GameState.WAITING); ListenerRegistration a1 = newRegistration(GameState.ACTIVE); List<ListenerRegistration> registrations = new ArrayList<>(Arrays.asList(w1, w2, a1)); runTest(listenerRegistrationService -> { listenerRegistrationService.gameStateChanged(GameState.WAITING); verify(pluginManager).registerEvents(eq(w1.getListener()), any()); verify(pluginManager).registerEvents(eq(w2.getListener()), any()); verifyZeroInteractions(listenerUnregister); reset(listenerUnregister, pluginManager); listenerRegistrationService.gameStateChanged(GameState.ACTIVE); verify(pluginManager).registerEvents(eq(a1.getListener()), any()); verify(listenerUnregister).unregister(eq(w1.getListener())); verify(listenerUnregister).unregister(eq(w2.getListener())); }, registrations); }
@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); }