### Question:
Listeners implements Iterable<T> { @Deprecated public void notify( Notification<T> notification ) { requireNonNull( notification, "notification can't be null" ); for ( T listener : listeners ) { notifySingleListener( listener, notification ); } } @Deprecated  Listeners(); @Deprecated  Listeners( Listeners<T> other ); @Deprecated void add( T listener ); @Deprecated void remove( T listener ); @Deprecated void notify( Notification<T> notification ); @Deprecated void notify( Executor executor, Notification<T> notification ); @Override Iterator<T> iterator();  }### Answer:
@Test void notifyWithNullNotification() { assertThrows( NullPointerException.class, () -> new Listeners<>().notify( null ) ); }
@Test void notifyWithNotification() { String message = "foo"; Listener listener1 = new Listener(); Listener listener2 = new Listener(); Listeners<Listener> listeners = newListeners( listener1, listener2 ); listeners.notify( listener -> listener.process( message ) ); assertEquals( message, listener1.message ); assertEquals( currentThread().getName(), listener1.threadName ); assertEquals( message, listener2.message ); assertEquals( currentThread().getName(), listener2.threadName ); }
@Test void notifyWithNullExecutorAndNullNotification() { assertThrows( NullPointerException.class, () -> new Listeners<>().notify( null, null ) ); }
@Test void notifyWithNullExecutorAndNotification() { assertThrows( NullPointerException.class, () -> new Listeners<Listener>().notify( null, listener -> listener.process( "foo" ) ) ); }
@Test void notifyWithExecutorAndNullNotification() { assertThrows( NullPointerException.class, () -> new Listeners<Listener>().notify( newSingleThreadExecutor(), null ) ); }
@Test void notifyWithExecutorAndNotification() throws Exception { String message = "foo"; String threadNamePrefix = "test-thread"; Listener listener1 = new Listener(); Listener listener2 = new Listener(); Listeners<Listener> listeners = newListeners( listener1, listener2 ); ExecutorService executor = newSingleThreadExecutor( named( threadNamePrefix ) ); listeners.notify( executor, listener -> listener.process( message ) ); executor.shutdown(); executor.awaitTermination( 1, TimeUnit.MINUTES ); assertEquals( message, listener1.message ); assertThat( listener1.threadName, startsWith( threadNamePrefix ) ); assertEquals( message, listener2.message ); assertThat( listener2.threadName, startsWith( threadNamePrefix ) ); }