PluginWatcher { void start(final String pluginDir, final ExecutorService executor, final PluginJarProcessor pluginJarProcessor) throws IOException { final Path pluginsRootPath = Paths.get(pluginDir); if (active || !Files.exists(pluginsRootPath)) { return; } this.active = true; this.executor = executor; this.pluginJarProcessor = pluginJarProcessor; final WatchService watchService = FileSystems.getDefault().newWatchService(); pluginsRootPath.register(watchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); startWatchService(watchService); }    }
@Test public void startSubmitsWatcherThread() throws Exception { pluginWatcher.start(pluginDir, executor, pluginJarProcessor); verify(executor, times(1)).submit(any(Runnable.class)); }
@Test public void startDoesNotSubmitWatcherThreadIfPluginDirDoesNotExist() throws Exception { pluginWatcher.start(pluginDir + "invalid", executor, pluginJarProcessor); verify(executor, never()).submit(any(Runnable.class)); }
@Test public void startOnlyOnce() throws Exception { pluginWatcher.start(pluginDir, executor, pluginJarProcessor); pluginWatcher.start(pluginDir, executor, pluginJarProcessor); verify(executor, times(1)).submit(any(Runnable.class)); }