ConfigurationChangeCoordinator implements Closeable, ConfigurationChangeNotifier { public Collection<ListenerHandleResult> notifyListeners(ByteBuffer newConfig) { logger.info("Notifying Listeners of a change"); Collection<ListenerHandleResult> listenerHandleResults = new ArrayList<>(configurationChangeListeners.size()); for (final ConfigurationChangeListener listener : getChangeListeners()) { ListenerHandleResult result; try { listener.handleChange(new ByteBufferInputStream(newConfig.duplicate())); result = new ListenerHandleResult(listener); } catch (ConfigurationChangeException ex) { result = new ListenerHandleResult(listener, ex); } listenerHandleResults.add(result); logger.info("Listener notification result:" + result.toString()); } return listenerHandleResults; }  void initialize(Properties properties, ConfigurationFileHolder configurationFileHolder, Collection<ConfigurationChangeListener> changeListenerSet); void start(); Set<ConfigurationChangeListener> getChangeListeners(); Collection<ListenerHandleResult> notifyListeners(ByteBuffer newConfig); @Override void close(); static final String NOTIFIER_PROPERTY_PREFIX; static final String NOTIFIER_INGESTORS_KEY; }
@Test public void testNotifyListeners() throws Exception { final ConfigurationChangeListener testListener = Mockito.mock(ConfigurationChangeListener.class); coordinatorSpy.initialize(properties, Mockito.mock(ConfigurationFileHolder.class), Collections.singleton(testListener)); Assert.assertEquals("Did not receive the correct number of registered listeners", coordinatorSpy.getChangeListeners().size(), 1); coordinatorSpy.notifyListeners(ByteBuffer.allocate(1)); verify(testListener, Mockito.atMost(1)).handleChange(Mockito.any(InputStream.class)); }