@Test void removeWatchers() { LanguageClient client = mock(LanguageClient.class); ClientProvider provider = new ClientProvider(); provider.set(client); ArgumentCaptor<UnregistrationParams> captor = forClass(UnregistrationParams.class); WatcherService watcherService = new WatcherServiceImpl(provider); watcherService.addWatchers(List.of("foo/bar", "baz", "bar\\foo")); watcherService.removeWatchers(List.of("non-existing", "foo/bar")); assertEquals(List.of("baz", "bar\\foo"), watcherService.getWatchingFolders()); verify(client).unregisterCapability(captor.capture()); UnregistrationParams params = captor.getValue(); List<Unregistration> unregistrations = params.getUnregisterations(); assertEquals(1, unregistrations.size()); Unregistration unregistration = unregistrations.get(0); assertEquals("foo/bar", unregistration.getId()); assertEquals("workspace/didChangeWatchedFiles", unregistration.getMethod()); }
@Override @Synchronized public void removeWatchers(@Nonnull List<String> paths) { List<String> removedWatchers = paths.stream().filter(folderWatchers::remove).collect(toList()); if (!removedWatchers.isEmpty()) { clientProvider .get() .unregisterCapability( new UnregistrationParams( removedWatchers.stream() .map(it -> new Unregistration(it, WATCH_FILES)) .collect(toList()))); } }
WatcherServiceImpl implements WatcherService { @Override @Synchronized public void removeWatchers(@Nonnull List<String> paths) { List<String> removedWatchers = paths.stream().filter(folderWatchers::remove).collect(toList()); if (!removedWatchers.isEmpty()) { clientProvider .get() .unregisterCapability( new UnregistrationParams( removedWatchers.stream() .map(it -> new Unregistration(it, WATCH_FILES)) .collect(toList()))); } } }
WatcherServiceImpl implements WatcherService { @Override @Synchronized public void removeWatchers(@Nonnull List<String> paths) { List<String> removedWatchers = paths.stream().filter(folderWatchers::remove).collect(toList()); if (!removedWatchers.isEmpty()) { clientProvider .get() .unregisterCapability( new UnregistrationParams( removedWatchers.stream() .map(it -> new Unregistration(it, WATCH_FILES)) .collect(toList()))); } } @Inject  WatcherServiceImpl(Provider<LanguageClient> clientProvider); }
WatcherServiceImpl implements WatcherService { @Override @Synchronized public void removeWatchers(@Nonnull List<String> paths) { List<String> removedWatchers = paths.stream().filter(folderWatchers::remove).collect(toList()); if (!removedWatchers.isEmpty()) { clientProvider .get() .unregisterCapability( new UnregistrationParams( removedWatchers.stream() .map(it -> new Unregistration(it, WATCH_FILES)) .collect(toList()))); } } @Inject  WatcherServiceImpl(Provider<LanguageClient> clientProvider); @Nonnull List<String> getWatchingFolders(); @Override void watchConfigurationChange(); @Override void watchPredefinedFolder(); @Override @Synchronized void addWatchers(@Nonnull List<String> paths); @Override @Synchronized void removeWatchers(@Nonnull List<String> paths); }
WatcherServiceImpl implements WatcherService { @Override @Synchronized public void removeWatchers(@Nonnull List<String> paths) { List<String> removedWatchers = paths.stream().filter(folderWatchers::remove).collect(toList()); if (!removedWatchers.isEmpty()) { clientProvider .get() .unregisterCapability( new UnregistrationParams( removedWatchers.stream() .map(it -> new Unregistration(it, WATCH_FILES)) .collect(toList()))); } } @Inject  WatcherServiceImpl(Provider<LanguageClient> clientProvider); @Nonnull List<String> getWatchingFolders(); @Override void watchConfigurationChange(); @Override void watchPredefinedFolder(); @Override @Synchronized void addWatchers(@Nonnull List<String> paths); @Override @Synchronized void removeWatchers(@Nonnull List<String> paths);  }