AbstractSignalNotificationHandler { public boolean unregisterListener(final SignalListener listener) { boolean unregistered = false; for (Signal signal : Signal.values()) { unregistered |= unregisterListener(listener, signal); } return unregistered; } protected  AbstractSignalNotificationHandler(); boolean registerListener(final SignalListener listener); boolean unregisterListener(final SignalListener listener);  }
@Test public void unregisterListener() { AbstractSignalNotificationHandler signalHandler = createSignalNotificationHandler(); SignalListener mockSignalListener = mock(SignalListener.class, "SIGALL"); assertThat(signalHandler.isListening(mockSignalListener)).isFalse(); assertThat(signalHandler.registerListener(mockSignalListener)).isTrue(); assertThat(signalHandler.isListening(mockSignalListener)).isTrue(); for (Signal signal : Signal.values()) { assertThat(signalHandler.hasListeners(signal)).isTrue(); } assertThat(signalHandler.unregisterListener(mockSignalListener)).isTrue(); assertThat(signalHandler.isListening(mockSignalListener)).isFalse(); for (Signal signal : Signal.values()) { assertThat(signalHandler.hasListeners(signal)).isFalse(); } assertThat(signalHandler.unregisterListener(mockSignalListener)).isFalse(); }
@Test public void unregisterListenerWithSignalListenerAndNullSignalThrowsNullPointerException() { assertThatThrownBy(() -> createSignalNotificationHandler() .unregisterListener(mock(SignalListener.class, "SIGALL"), null)) .isInstanceOf(NullPointerException.class) .hasMessage("The signal from which to unregister the listener cannot be null!"); }