I have a scala class which uses the java nio WatchService to detect creation of new folders in a specific directory.
The WatchService works well when the app is running and I manually copy a folder into the target folder.
I have created a unit test using scalatest that initializes my class and copies a test folder into the target folder using Apache Commons
FileUtils.copyDirectory(testFolder, new File(targetFolder, testFolder.getName), false)
The watch service does not detect any new entry created in the target folder within 30 seconds. My code is inside an eventually block similar to
eventually(timeout(Span(30, Seconds)), interval(Span(1, Seconds))) {
// CHECK IF THE SERVICE DETECTED THE NEW ENTRY
}
Any idea why this does not work in unit tests?