monitor.addWatch(subdir1);
monitor.addWatch(subdir2);
// trigger change in dir 1
File file = File.createTempFile(getName(), ".tmp", subdir1);
FileEvent event = (FileEvent)events.get(new Integer(FileMonitor.FILE_CREATED));
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 5000 && event == null) {
Thread.sleep(10);
event = (FileEvent)events.get(new Integer(FileMonitor.FILE_CREATED));
}
assertTrue("No events sent", events.size() != 0);
assertNotNull("No creation event: " + events, event);
assertEquals("Wrong target file for event", file, event.getFile());
events.clear();
// trigger change in dir 2
file = File.createTempFile(getName(), ".tmp", subdir2);
event = (FileEvent)events.get(new Integer(FileMonitor.FILE_CREATED));
start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 5000 && event == null) {
Thread.sleep(10);
event = (FileEvent)events.get(new Integer(FileMonitor.FILE_CREATED));
}
assertTrue("No events sent", events.size() != 0);
assertNotNull("No creation event: " + events, event);
assertEquals("Wrong target file for event", file, event.getFile());
// trigger change in dir 1
file = File.createTempFile(getName(), ".tmp", subdir1);
event = (FileEvent)events.get(new Integer(FileMonitor.FILE_CREATED));
start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 5000 && event == null) {
Thread.sleep(10);
event = (FileEvent)events.get(new Integer(FileMonitor.FILE_CREATED));
}
assertTrue("No events sent", events.size() != 0);
assertNotNull("No creation event: " + events, event);
assertEquals("Wrong target file for event", file, event.getFile());
}
finally {
delete(subdir1);
delete(subdir2);
}