/** * Sets everything up for a test: retrieves a temporary file instance, create the file, waits until the file exists, * create a <code>FileMonitor</code>, register a {@link FileChangeTracker} and finally start monitoring file changes. * * @param attribute the attribute to monitor * @throws IOException should not normally happen */ private void setUp(int attribute) throws IOException { // Retrieve a temporary AbstractFile instance that will be deleted on VM shutdown file = FileFactory.getTemporaryFile(getClass().getName(), true); // Create the file file.mkfile(); // Waits until the file truly exists (I/O are usually asynchroneous) while(!file.exists()) { try { Thread.sleep(POLL_PERIOD); } catch(InterruptedException e) {} } // Create the monitor, change listener and start monitoring file changes fileMonitor = new FileMonitor(file, attribute, POLL_PERIOD); fileChangeTracker = new FileChangeTracker(); fileMonitor.addFileChangeListener(fileChangeTracker); fileMonitor.startMonitoring(); }