ConfigDispatcherFileWatcher extends AbstractWatchService { @Override protected void processWatchEvent(WatchEvent<?> event, Kind<?> kind, Path path) { if (kind == ENTRY_CREATE || kind == ENTRY_MODIFY) { File f = path.toFile(); if (!f.isHidden() && f.getName().endsWith(".cfg")) { configDispatcher.processConfigFile(f); } } else if (kind == ENTRY_DELETE) { File configFile = path.toFile(); if (configFile.isHidden() || configFile.isDirectory() || !configFile.getName().endsWith(".cfg")) { return; } configDispatcher.fileRemoved(configFile.getAbsolutePath()); } } @Activate  ConfigDispatcherFileWatcher(final @Reference ConfigDispatcher configDispatcher); @Activate @Override void activate(); @Deactivate @Override void deactivate(); static final String SERVICEDIR_PROG_ARGUMENT; static final String SERVICES_FOLDER; }
@Test public void configurationFileCreated() { String path = "myPath.cfg"; configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_CREATE, new File(path).toPath()); verify(configDispatcher).processConfigFile(new File(path)); }
@Test public void configurationFileModified() { String path = "myPath.cfg"; configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_MODIFY, new File(path).toPath()); verify(configDispatcher).processConfigFile(new File(path)); }
@Test public void nonConfigurationFileCreated() { String path = "myPath"; configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_CREATE, new File(path).toPath()); verifyNoInteractions(configDispatcher); }
@Test public void nonConfigurationFileModified() { String path = "myPath"; configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_MODIFY, new File(path).toPath()); verifyNoInteractions(configDispatcher); }
@Test public void configurationFileRemoved() { String path = "myPath.cfg"; configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_DELETE, new File(path).toPath()); verify(configDispatcher).fileRemoved(new File(path).getAbsolutePath()); }
@Test public void nonConfigurationFileRemoved() { String path = "myPath"; configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_DELETE, new File(path).toPath()); verifyNoInteractions(configDispatcher); }