SyncManager implements ChangeHandler { protected File getWatchDir(File changedFile) { for (File watchDir : watchDirs) { File changedFileParent = changedFile.getParentFile(); while (changedFileParent != null) { if (changedFileParent.equals(watchDir)) { return watchDir; } else { changedFileParent = changedFileParent.getParentFile(); } } } return null; } SyncManager(List<File> watchDirs,
                       SyncEndpoint endpoint,
                       int threads,
                       long frequency); void beginSync(); void endSync(); void terminateSync(); synchronized boolean handleChangedFile(ChangedFile changedFile); synchronized List<MonitoredFile> getFilesInTransfer();  }
@Test public void testGetWatchDir() throws Exception { File tempDir1 = new File("/a/b"); File tempDir2 = new File("/a/c"); List<File> watchDirs = new ArrayList<File>(); watchDirs.add(tempDir1); watchDirs.add(tempDir2); SyncManager syncManager = new SyncManager(watchDirs, new TestEndpoint(), 2, 100); assertEquals(tempDir1, syncManager.getWatchDir(new File("/a/b/file.txt"))); assertEquals(tempDir2, syncManager.getWatchDir(new File("/a/c/file.txt"))); assertEquals(tempDir1, syncManager.getWatchDir(new File("/a/b/q/r/file.txt"))); assertEquals(tempDir2, syncManager.getWatchDir(new File("/a/c/t/u/file.txt"))); assertNull(syncManager.getWatchDir(new File("/d/file.txt"))); }