FileChangeIngestor implements Runnable, ChangeIngestor { @Override public void run() { logger.debug("Checking for a change"); if (targetChanged()) { logger.debug("Target changed, checking if it's different than current flow."); try (FileInputStream configFile = new FileInputStream(configFilePath.toFile()); ByteArrayOutputStream pipedOutputStream = new ByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream(configFile, pipedOutputStream)) { if (differentiator.isNew(teeInputStream)) { logger.debug("New change, notifying listener"); while (teeInputStream.available() != 0) { teeInputStream.read(); } ByteBuffer newConfig = ByteBuffer.wrap(pipedOutputStream.toByteArray()); ByteBuffer readOnlyNewConfig = newConfig.asReadOnlyBuffer(); configurationChangeNotifier.notifyListeners(readOnlyNewConfig); logger.debug("Listeners notified"); } } catch (Exception e) { logger.error("Could not successfully notify listeners.", e); } } }  @Override void run(); @Override void initialize(Properties properties, ConfigurationFileHolder configurationFileHolder, ConfigurationChangeNotifier configurationChangeNotifier); @Override void start(); @Override void close(); static final String DIFFERENTIATOR_KEY; }
@Test public void testTargetChangedWithModificationEvent() throws Exception { when(mockDifferentiator.isNew(Mockito.any(InputStream.class))).thenReturn(true); final WatchKey mockWatchKey = createMockWatchKeyForPath(CONFIG_FILENAME); establishMockEnvironmentForChangeTests(testNotifier, mockWatchKey); notifierSpy.run(); verify(mockWatchService, Mockito.atLeastOnce()).poll(); verify(testNotifier, Mockito.atLeastOnce()).notifyListeners(Mockito.any(ByteBuffer.class)); }