### Question:
DefaultFileSystemWatcher implements FileWatcher { @Override public WatchedResource watch( File file ) throws IOException { if ( !file.isDirectory() ) { throw new IllegalArgumentException( format( "File `%s` is not a directory. Only directories can be " + "registered to be monitored.", file.getCanonicalPath() ) ); } WatchKey watchKey = file.toPath().register( watchService, OBSERVED_EVENTS, SensitivityWatchEventModifier.HIGH ); return new WatchedFile( watchKey ); } DefaultFileSystemWatcher( WatchService watchService ); @Override WatchedResource watch( File file ); @Override void startWatching(); @Override void stopWatching(); @Override void addFileWatchEventListener( FileWatchEventListener listener ); @Override void removeFileWatchEventListener( FileWatchEventListener listener ); @Override void close();  }### Answer:
@Test void fileWatchRegistrationIsIllegal() { DefaultFileSystemWatcher watcher = createWatcher(); IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> watcher.watch( new File( "notADirectory" ) ) ); assertThat( exception.getMessage(), containsString( "Only directories can be registered to be monitored." ) ); }
@Test void registerMultipleDirectoriesForMonitoring() throws Exception { try ( DefaultFileSystemWatcher watcher = new DefaultFileSystemWatcher( FileSystems.getDefault().newWatchService() ) ) { File directory1 = testDirectory.directory( "test1" ); File directory2 = testDirectory.directory( "test2" ); WatchedResource watchedResource1 = watcher.watch( directory1 ); WatchedResource watchedResource2 = watcher.watch( directory2 ); assertNotSame( watchedResource1, watchedResource2 ); } }