/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.filesystems; import java.io.File; import org.netbeans.junit.NbTestCase; /** * Test that file events are propagated up a tree. * @author Jesse Glick */ public class HierarchicalFileEventsTest extends NbTestCase { public HierarchicalFileEventsTest(String name) { super(name); } private File scratch; private LocalFileSystem lfs; private FileObject root; protected void setUp() throws Exception { super.setUp(); clearWorkDir(); scratch = getWorkDir(); lfs = new LocalFileSystem(); lfs.setRootDirectory(scratch); root = lfs.getRoot(); } /** * Checks that a file creation event is passed up the tree to any listeners * that may be found. */ public void testFileCreatedEventPassedUp() throws Exception { L l = new L(); root.addFileChangeListener(l); // NOT lfs.addFileChangeListener(l) FileObject subdir = root.createFolder("subdir"); assertEquals("got a folder creation event with the right source", root, l.source); assertEquals("got a folder creation event with the right target", subdir, l.target); l.source = null; l.target = null; FileObject file = subdir.createData("file"); assertEquals("got a file creation event with the right source", root, l.source); assertEquals("got a file creation event with the right target", file, l.target); } private static final class L extends FileChangeAdapter { public FileObject source, target; L() {} public void fileDataCreated(FileEvent fe) { source = (FileObject)fe.getSource(); target = fe.getFile(); } public void fileFolderCreated(FileEvent fe) { source = (FileObject)fe.getSource(); target = fe.getFile(); } } }